-1

I'm having trouble understanding something about Content Negotiation in HTTP protocol.

I understand that when the header Accept is sent in a request, it's telling the server that it expects the response in that format.

For instance, if the Header Accept have the value application/json then the server must send the response in JSON format. If it can't do this, it sends the HTTP error 406 Not Acceptable (although most web applications don't do it because the end user would not understand want happen. This is specified so in documentation https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406).

My problem is if the request send in the header Content-Type the format in which it intends to receive the representation of the resource in the response, and the server application respects this mechanism (content negotiation) then the header Content-Type of the response must have the same value if not, then it must be returned the HTTP error 406 Not Acceptable?

RuiDTLima
  • 35
  • 1
  • 9

1 Answers1

1

The HTTP specification says:

If an Accept header field is present, and if the server cannot send a response which is acceptable according to the combined Accept field value, then the server SHOULD send a 406 (not acceptable) response.

Note that "SHOULD" means:

This word, or the adjective "RECOMMENDED", mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

So what you think is not true.

  • Maybe my question wasn't clear, but i realize that about the Accept header, my problem is if the same thing happen with the header Content-Type in a get request to specify the format of the response the server must send. – RuiDTLima Jan 26 '18 at 13:13
  • Your question is not clear, indeed. Note that MUST is not the same as SHOULD. –  Jan 26 '18 at 13:14
  • Sorry about that. I thought that it was clear since i mention that it MUST if the server application respects the Content negotiation mechanism. – RuiDTLima Jan 26 '18 at 13:17
  • No, you misunderstand the specifications. The server SHOULD. It can behave different from what you expect if there are good reasons. –  Jan 26 '18 at 13:24