Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple content length headers and multiple transfer encoding headers

Tags:

http

If there are multiple content length headers, should I

  1. fail (I don't think so?)
  2. use the first one,
  3. use the last one

Then I have the same question for transfer_encoding header too. I think with transfer_encoding we are supposed to use the last one.

then, same question for 'Host' header as well.

thanks, Dean

like image 885
Dean Hiller Avatar asked Mar 13 '23 10:03

Dean Hiller


2 Answers

Content-Length is a single-value header. Usually the last header would have authority; however RFC 7230, section 3.3.2 states:

If a message is received that has multiple Content-Length header fields with field-values consisting of the same decimal value, or a single Content-Length header field with a field value containing a list of identical decimal values (e.g., "Content-Length: 42, 42"), indicating that duplicate Content-Length header fields have been generated or combined by an upstream message processor, then the recipient MUST either reject the message as invalid or replace the duplicated field-values with a single valid Content-Length field containing that decimal value prior to determining the message body length or forwarding the message.

Transfer-Encoding is a different matter as it is containing a list. There can be multiple ones and all are valid. The important thing here is that applied encodings have to be listed in the order in which they have been applied. E.g. if content has been gzipped and then chunk-encoded, the headers have to look like

Transfer-Encoding: gzip, chunked

or

Transfer-Encoding: gzip
Transfer-Encoding: chunked
like image 68
DaSourcerer Avatar answered Apr 19 '23 23:04

DaSourcerer


WRT Content-Length: yes, you actually MUST fail (unless both values are the same, in which case you MAY pick one). See RFC 7230.

"Transfer-Encoding" is different in that it allows multiple values; so you'll have to process them all in order.

like image 34
Julian Reschke Avatar answered Apr 20 '23 01:04

Julian Reschke