Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard for adding multiple values of a single HTTP Header to a request or response

If I want to add a list of values as an HTTP Header, is there a standard way to do this? I couldn't find anything (that I could easily understand) in RFC 822. For example, is comma separated values standard or semi-colon separated values. Is there a standard at all?

Example:

Key: value1;value2;value3 
like image 533
jconlin Avatar asked Jun 22 '10 20:06

jconlin


People also ask

Can a HTTP header have multiple values?

The HTTP Headers can have one or more values depending on the header field definitions. A multi-valued header will have comma separated values.

What is the maximum size of HTTP header values?

No, HTTP does not define any limit. However most web servers do limit size of headers they accept. For example in Apache default limit is 8KB, in IIS it's 16K. Server will return 413 Entity Too Large error if headers size exceeds that limit.


1 Answers

You'll want to take a look at the HTTP spec RFC 2616 where it says:

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

What this means is that you can send the same header multiple times in a response with different values, as long as those values can be appended to each other using a comma. This also means that you can send multiple values in a single header by concatenating them with commas.

So in your case it will be:

Key: value1,value2,value3 
like image 89
Marc Novakowski Avatar answered Oct 07 '22 05:10

Marc Novakowski