3

According to the HTTP1.1 spec, an Accept header of the following

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

is interpreted to mean

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

Let's change the header to:

Accept: text/html, text/x-c

What is returned if neither of this is accepted ? e.g. let's pretend that I only support application/json

3 Answers 3

4

Maybe you should respond with a 406 Not Acceptable. That's how I read this.

Or a 415 Unsupported Media Type?

I would opt for a 406, because in that case and according to the specs, a response SHOULD include a list of alternatives. Although is not clear to me how that list should look like.

Sign up to request clarification or add additional context in comments.

2 Comments

406 is correct in this case. 415 is for the case where a Client submits data (e.g. via POST) with a Content-Type the application can't handle.
Or you can send the requested entity in a format not specified in the request ACCEPT header, as noted in the specification for the 406 status code.
2

"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." -- RFC2616, Section 14.1

Comments

1

You have a choice. You can either reply with 406 and include an "entity" (e.g. HTML or text file) describing the available formats; OR if you are using HTTP 1.1, you can send the format you support even though it wasn't listed in the Accept header.

(see section 10.4.7 of RFC 2616)

"Note: HTTP/1.1 servers are allowed to return responses which are not acceptable according to the accept headers sent in the request. In some cases, this may even be preferable to sending a 406 response. User agents are encouraged to inspect the headers of an incoming response to determine if it is acceptable."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.