HTTP - Accept header

About

accept is a request header that specify the mimes type of the response body that are accepted by the client (ie browser)

Syntax

Without

If no Accept header field is present, then it is assumed that the client accepts all media types.

With

In abnf

Accept         = "Accept" ":" *( media-range [ accept-params ] )
media-range    = ( "*/*"  | ( type "/" "*" ) | ( type "/" subtype ) ) *( ";" parameter )
accept-params  = ";" "q" "=" qvalue *( accept-extension )
accept-extension = ";" token [ "=" ( token | quoted-string ) ]

where:

  • the accept header can have multiple MIME types separated by ,
  • the media range:
    • */* indicating all media types
    • type/* indicating all subtypes of that type.
  • the q parameter (default value = 1) is a number between 0 and 1.0 that indicates :
    • a relative quality factor.
    • or a relative degree of preference (a weighting) to apply if more than one response MIME type is available

Response

The response would define the mime type of the body with the content-type header.

If no media of the requested type can be send, the response status should be a 406 - Not acceptable

Example

  • audio/basic is preferred, but any audio type with a 80% mark-down in quality is also accepted.
Accept: audio/*; q=0.2, audio/basic
  • Accept text/plain or text/html with no preference
Accept: text/plain, text/html
  • Accept text/plain or text/html with a prefernce for text/html as it has a higher q value (it has the default q=1.0)
Accept: text/plain; q=0.9, text/html
Accept: text/css,*/*;q=0.1
Accept: */*
Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8

Documentation / Reference





Discover More
HTML - Icon (Shortcut|Favicon)

Icon The Shortcut (or Favicon) Pinned Tab icons ... The default favicon searched by the browser is: at the root of the website with an ico format and the name favicon.ico It's equivalent...
Chrome Devtool Har
HTTP - Request

An HTTP request is a message sent from a client to a server. It's the first part of a fetch, the second being the response. A request message has: a first line called the request...
What are the HTTP status code 4XX?

HTTP - 4XX status code All status code that begins with the number 4 are error code. Meaning that an error has occurred during the request and that the server may use any of this code to send feedback...
Cors Flowchart
What is Cross Origin Resource Sharing (CORS) ?

What is Cross Origin Resource Sharing (CORS) ? Cross-origin resource sharing (CORS) is a mechanism that: allows a HTTP server to control the cross-origin requests executed by a browser. In short,...
What is the HTTP Content-Type Header?

The Content-Type is a http header that defines the data type of the body of: a request or a response. It specifies: the mime type (mandatory) and optionally the parameters of the mime: such...



Share this page:
Follow us:
Task Runner