Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Accept-Encoding and sending unencoded data

I building a module for compressing HTTP output. Reading the spec, I haven't found a clear distinction on a couple of things:

Accept-Encoding:

Should this be treated the same as a Accept-Encoding: * or as if no header is present?

Or what if I don't support gzip, but I get a header like this:

Accept-Encoding: gzip

Should I return a 406 error or just return the data unencoded?

EDIT:

I've read over the spec a few times. It mentions my first case, but it doesn't define what the behavior of the server should be.

Should I treat this case as if the header is not present? Or should I return a 406 error because there's no way to encode something given the field value ('' isn't a valid encoding).

like image 891
beatgammit Avatar asked Jul 14 '11 02:07

beatgammit


People also ask

What is HTTP accept-encoding?

The Accept-Encoding request HTTP header indicates the content encoding (usually a compression algorithm) that the client can understand. The server uses content negotiation to select one of the proposals and informs the client of that choice with the Content-Encoding response header.

Are HTTP requests encoded?

The HTTP request and response body are encoded using the text encoding specified in the charset attribute of the Content-Type header.

What is content encoding HTTP?

Content encoding is mainly used to compress the message data without losing information about the origin media type. Note that the original media/content type is specified in the Content-Type header, and that the Content-Encoding applies to the representation, or "coded form", of the data.

Is accept-encoding required?

Accept-encoding header is an HTTP header which must be included on every origin server response. Its main job is to inform the browsers if the client can handle the compressed version of the website. The warning can appear when you don't use the Vary: Accept-Encoding in your header on a server or CDN.


1 Answers

There is written everything in the Spec: 14.3 Accept-Encoding:

The special "*" symbol in an Accept-Encoding field matches any available content-coding not explicitly listed in the header field.

If an Accept-Encoding field is present in a request, and if the server cannot send a response which is acceptable according to the Accept-Encoding header, then the server SHOULD send an error response with the 406 (Not Acceptable) status code.

edit:

If the Accept-Encoding field-value is empty, then only the "identity" encoding is acceptable.

In this case, if "identity" is one of the available content-codings, then the server SHOULD use the "identity" content-coding, unless it has additional information that a different content-coding is meaningful to the client.

What is "identity"

identity
The default (identity) encoding; the use of no transformation whatsoever. This content-coding is used only in the Accept- Encoding header, and SHOULD NOT be used in the Content-Encoding header.

like image 86
timaschew Avatar answered Sep 23 '22 04:09

timaschew