Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret HTTP Accept headers?

Tags:

rest

http

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

like image 809
Jacques René Mesrine Avatar asked May 09 '26 03:05

Jacques René Mesrine


2 Answers

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.

like image 186
Ionuț G. Stan Avatar answered May 10 '26 23:05

Ionuț G. Stan


"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

like image 45
Julian Reschke Avatar answered May 10 '26 23:05

Julian Reschke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!