19

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")?

oligofren
  • 20,744
  • 16
  • 93
  • 180
Zag zag..
  • 6,041
  • 6
  • 27
  • 36

2 Answers2

30

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

dsign
  • 12,340
  • 6
  • 59
  • 82
  • Reference? I don't see one. I have tried searching, and your answer comes up, but it is hardly authorative. – oligofren Jun 01 '18 at 08:39
  • 1
    @dsign 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](https://github.com/sinonjs/nise/pull/53) 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 :) – oligofren Jun 04 '18 at 08:12
9

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):

oligofren
  • 20,744
  • 16
  • 93
  • 180