🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

Accept

HTTP Header

The HTTP Accept request and response headers specify which content types, expressed as MIME types, the sender can interpret.
During a request, the server employs content negotiation to select one of the acceptable content types and informs the client of this selection using the Content-Type response header.
In reply, the server indicates which content types it can understand in messages relevant to the requested resource, enabling the client to utilize this information in future requests to the same resource.

Browsers determine appropriate values for this header based on the context of the request.
For example, different values are used when fetching CSS stylesheets, images, videos, or scripts.

The following table summarizes the types of headers involved:

Header typeRequest header, Response header
Forbidden request headerNo
CORS-safelisted request headerYes*

 

* Values cannot contain CORS-unsafe request header bytes, including “( ) : < > ? @ [ ] { } ,” also delete 0x7F and control characters 0x00 to 0x19, except for Tab 0x09.

Syntax

Accept: <media-type>/<MIME_subtype>
Accept: <media-type>/*
Accept: */*
 

// Multiple types, weighted with the quality value syntax
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8

Directives

<media-type>/<subtype>

A specific and precise media type, such as text/html. This indicates exactly what type of data is being referred to.

<media-type>/*

A media type without a specific subtype. For example, image/* includes all image formats such as image/png, image/svg, and image/gif.

*/*

Represents any media type without restriction.

;q= (q-factor weighting)

Indicates the relative preference or quality level for a media type through a quality value, known as the weight.

Example

HTTP requests made using command line tools such as curl and wget typically default to using */* as the Accept header value:

http
GET / HTTP/1.1
Host: example.com
User-Agent: curl/8.7.1
Accept: */*

Browser navigation usually includes the following Accept header in requests:

http
GET /en-US/ HTTP/2
Host: developer.mozilla.org
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
…

Once the document is received, the default Accept headers used when requesting images from the developer.mozilla.org website include:

http
Accept: image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5

Configuring Accept request headers for JSON responses

Systems that interact with APIs often request application/json responses.
Here is an example of a GET request where the client explicitly requests a JSON response:

http
GET /users/123 HTTP/1.1
Host: example.com
Authorization: Bearer abcd123
Accept: application/json

How to Modify Header using Requestly

Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Accept header. This is especially useful for testing how your application responds to different media types during development or debugging. Steps to Modify the Accept Header:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. Add a new header modification:
    • Under “Action”, select “Add” or “Override”.
    • In the “Header Name” field, enter Accept.
    • In the “Header Value” field, enter your preferred media type (e.g., text/html).
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
  5. Save the rule.

Once set up, Requestly will inject the Accept: text/html header into all matching requests, allowing you to simulate different client behaviors and test content negotiation on your server.
You might need to modify the Accept header to test how your website or API responds to various content types like JSON, XML, or HTML. This helps ensure your application handles different formats correctly and improves the overall user experience.