How to interpret HTTP Accept headers?

According to the HTTP1.1 specification, the Accept header of the following

Accept: text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c

interpreted as meaning

text/html and text/x-c are the preferred media types, but if they do not 
exist, then send the text/x-dvi entity, and if that does not exist, send 
the text/plain entity

Change the title to:

Accept: text/html, text/x-c

What is returned if none of them are accepted? for example, suppose I only support the application / json

+3
source share
3 answers

Maybe you should answer 406 Not acceptable . This is how I read this one .

Or 415 unsupported media type ?

I would choose 406, because in this case and in accordance with the specifications, the answer SHOULD include a list of alternatives. Although it is not clear to me what this list looks like.

+4

" Accept, , Accept, 406 () ." - RFC2616, 14.1

+2

. 406 "" (, HTML ), ; , HTTP 1.1, , Accept.

(. 10.4.7 RFC 2616)

"Note: HTTP / 1.1 servers are allowed to return responses that are not acceptable according to the acceptance sent in the request. In some cases, it may even be preferable to send a 406 response. User agents are advised to check the headers of the incoming response to determine if this is acceptable."

+1
source

Source: https://habr.com/ru/post/1706872/


All Articles