HTTP - Accept header

1 - About

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

3 - Syntax

3.1 - Without

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

3.2 - 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

4 - 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

5 - 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

  • Send for Javascript script

Accept: */*


Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8

6 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap