5

In my application(node/express), I have to call a third party server to read some data. The response of the third party server will have custom header sessionId - Id being capitalized as per the document. But in my application, the custom header key is changed to sessionid - id in lowercase. I tested this behaviour in axios and request-promise http client.

Why upper case in header key is converted to lowercase in node/express?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Manikandan J
  • 144
  • 1
  • 6

1 Answers1

8

Express's Request object has a case-insensitive .get('header-name') method to look up headers. The way the Express team implemented the case-insensitivity is apparently to downcase the header names in when they store them.

Express does case-insensitive matching here to comply with RFC2616's specification that header names are to be case-insensitive. That means your third party server is free to return a header named sessionId, sessionid, SeSsIoNiD or whatever, and it still means sessionid to your own app. (RFC2616 is the formal specification for the HTTP protocol.)

Community
  • 1
  • 1
O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • Did you mean [`res.get()`](https://expressjs.com/en/4x/api.html#res.get) for testing a response? Otherwise, not understanding the use-case for getting the `Request` Headers, which should have been added via `req.set()` – OneCricketeer Sep 12 '22 at 18:27