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
- Send for Javascript script
Accept: */*
- Css Source Map file didn't have any
Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8