21

I'm trying to use curl to send a HTTP request with custom headers (curl http://example.com -H "Foo: bar"), and I'm finding that when the header arrives, it has been lower-cased, by curl (the above Foo header is received as foo: bar)

How to preserve the case of headers in a request?

5
  • 1
    HTTP headers are case insensitive so the case must not matter to anyone speaking HTTP proper... Jan 7, 2019 at 7:09
  • 3
    @DanielStenberg Except not everyone actually follows specs, which is the whole point of this question, since if you want (need?) to interact with someone who doesn't follow the specs, then you need to not follow them yourself, in the same specific way they don't. HTTP earlier than HTTP 2 was at least case preserving, and as such, if you tell curl to use HTTP 1.1 it will respect the case of the headers you tell it to set.
    – Phil
    Jan 8, 2019 at 1:17
  • 1
    HTTP was never "case preserving". It was always just case insensitive but some clients would preserve or enforce a special casing. curl for example typically passes on the casing used by the user - unless for HTTP/2 which is lowercase by spec. Jan 8, 2019 at 13:42
  • as I already said - not every server actually follows the spec. It seems kinda silly that a client library would not have an option to signify it was talking to such a broken server. feature request?
    – Phil
    Jan 9, 2019 at 18:19
  • modern curl doesn't do this :) (at least version 7.80.0, released 2021-11-10 doesn't do this)
    – hanshenrik
    Jan 28, 2022 at 15:22

1 Answer 1

43
+50

Try forcing curl to use HTTP/1.1 - it defaults to HTTP/2, the spec for which states that headers must be in lower case.

curl http://example.com --http1.1 -H "Foo: bar"
1
  • Take my upvote, I've been struggling on this issue for days.
    – zessx
    Jan 25, 2022 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.