upper case converted to lower case when reading response HEADER in node/express js with httpclients axios and request-promise
Asked Answered
F

1

7

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?

Feral answered 27/7, 2020 at 9:39 Comment(0)
C
12

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

Columbine answered 27/7, 2020 at 10:27 Comment(1)
Did you mean 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()Uturn

© 2022 - 2024 — McMap. All rights reserved.