Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling whitespaces in http headers

Tags:

http

Should leading or trailing whitespaces be ignored in an http request/response?

For example, should a HTTP/1.1 compliant client interpret this :

Connection  :   close      \r\n

as this :

Connection: close\r\n
like image 556
Kartal Kaan Bozdoğan Avatar asked Aug 02 '15 15:08

Kartal Kaan Bozdoğan


People also ask

Can 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 characters are allowed in HTTP header?

The value of the HTTP request header you want to set can only contain: Alphanumeric characters: a - z and A - Z. The following special characters: _ :;.,\/"'?!(){}[]@<>=-+*#$&`|~^%

Are headers case sensitive?

officially, headers are case insensitive, however, it is common practice to capitalize the first letter of every word.

Can HTTP header have empty value?

HTTP headers are key/value pairs sent at the beginning of a request or response. According to the grammar in RFC 7230, a field could have an empty value.


1 Answers

According with paragraph 4.2 of RFC2616 (HTTP/1.1), field values might be preceded by whitespace, but not the field name:

Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive. The field value may be preceded by any amount of LWS (linear white space), though a single SP is preferred. Header fields can be extended over multiple lines by preceding each extra line with at least one SP or HT. Applications ought to follow "common form", where one is known or indicated, when generating HTTP constructs, since there might exist some implementations that fail to accept anything.

like image 63
Little Santi Avatar answered Oct 27 '22 00:10

Little Santi