Possible types of a HTTP header value
Asked Answered
H

2

22

The type of a value passed through a query string is always a string. When a HTTP client need to send a number, let's say 42, in is actually "42". Everything inside the query string is actually a string.

Is it the same for the type of values passed through a header ?

In other words, if we send an HTTP request with a "FooBar" header with the value of 42, and another request where the value of the header set to "42", will the server perceive the two received values as of the same type and value (i.e. "42")?

Haywood answered 8/12, 2015 at 9:24 Comment(1)
Was wondering this today!Proportion
O
34

It's always a string, even in HTTP/2

Overstride answered 8/12, 2015 at 10:9 Comment(2)
Reference? I don't see one. I have tried searching, and your answer comes up, but it is hardly authorative.Strategist
@Overstride I tried doing my research, which landed my here. I was just asking if you had a reference, since I failed to find any, and as I am implicitly responsible for reimplementing parts of the spec I can't just trust some random assertion on the net. But through Wikipedia I was able to find RFC7230. High value answers with all the information one needs is one of the intended goals of SO, so I wasn't trying to offend you :)Strategist
S
11

tldr; Headers are text, sometimes ISO 8859, but usually just US-ASCII.

According to the 2014 RFC7230 (last paragraph), HTTP fields have used to be text and new headers should continue to do so, restricting the values to consist of US-ASCII octets.

The 1982 RFC822 specifies ASCII as the format of the header body.

References (found through List of HTTP Headers):

Strategist answered 4/6, 2018 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.