Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content-Encoding vs Transfer Encoding in HTTP

Tags:

http

rfc2616

I have a question on usage of Content-Encoding and Transfer-Encoding:

Please let me know if my below understanding is right:

Client in its request can specify which encoding types it is willing to accept using accept-encoding header. So, if Server wishes to encode the message before transmission, eg. gzip, it can zip the entity (content) and add content-encoding: gzip and send across the HTTP response. On reception, client can receive and decompress and parse the entity.

In case of Transfer Encoding, Client may specify what kind of encoding it is willing to accept and perform its action on fly. i.e. if Client sends a TE: gzip; q=1, it means that if Server wishes, it can send a 200 OK with Transfer-Encoding: gzip and as it tries sending the stream, it can compress and send across, and client upon receiving the content, can decompress on fly and perform its parsing.

Is my understanding right here? Please comment.

Also, what is the basic advantage of compressing the entity on fly vs compressing the entity first and then transmitting it across? Is transfer-encoding valid only for chunked responses as we do not know the size of the entity before transmission?

like image 976
Vamsi Mohan Avatar asked Jun 26 '14 06:06

Vamsi Mohan


People also ask

What is HTTP content encoding?

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.

What is content transfer encoding?

Content transfer encoding defines encoding methods for transforming binary email message data into the US-ASCII plain text format. This transformation allows the message to travel through older SMTP messaging servers that only support messages in US-ASCII text. Content transfer encoding is defined in RFC 2045.

What is the use of transfer encoding?

Transfer-Encoding is a hop-by-hop header, that is applied to a message between two nodes, not to a resource itself. Each segment of a multi-node connection can use different Transfer-Encoding values. If you want to compress data over the whole connection, use the end-to-end Content-Encoding header instead.

What is content encoding gzip?

Gzip is a file format and software application used on Unix and Unix-like systems to compress HTTP content before it's served to a client.


1 Answers

The difference really is not about on-the-fly or not -- Content-Encoding can be both pre-computed and on the fly.

The differences are:

  • Transfer Encoding is hop-by-hop, not end-to-end
  • Transfer Encodings other than "chunked" (sadly) aren't implemented in practice
  • Transfer Encoding is on the message layer, Content Encoding on the payload layer
  • Using Content Encoding affects entity tags etc.

See http://greenbytes.de/tech/webdav/rfc7230.html#transfer.codings and http://greenbytes.de/tech/webdav/rfc7231.html#data.encoding.

like image 153
Julian Reschke Avatar answered Oct 10 '22 14:10

Julian Reschke