Skip to content

Conversation

@seb-cr
Copy link
Contributor

@seb-cr seb-cr commented Dec 7, 2023

This is consistent with many other libraries (e.g. http, axios) and makes it easier to work with HTTP headers.

The HTTP protocol states that header names are case-insensitive, so currently when using getAllHeaders you must worry about the case of the header name:

const headers = request.getAllHeaders();
const contentType = headers['Content-Type'] || headers['content-type'];
// but what if someone sends us `Content-type`?

The existing getHeader method solved this by doing a case-insensitive search of all keys. Now, you can also safely use the lowercase key:

const headers = request.getAllHeaders();
const contentType = headers['content-type'];

Jira: ENG-2735

BREAKING CHANGE: Header keys returned by getAllHeaders are converted to lowercase. Accessing headers through non-lowercase keys will yield undefined, even if the header in the request is in the same case. Use lowercase keys, or use getHeader.

This is consistent with many other libraries (e.g. http, axios) and
makes it easier to work with HTTP headers.

The HTTP protocol states that header names are case-insensitive, so
currently when using `getAllHeaders` you must worry about the case of
the header name:

```js
const headers = request.getAllHeaders();
const contentType = headers['Content-Type'] || headers['content-type'];
// but what if someone sends us `Content-type`?
```

The existing `getHeader` method solved this by doing a case-insensitive
search of all keys. Now, you can also safely use the lowercase key:

```js
const headers = request.getAllHeaders();
const contentType = headers['content-type'];
```

BREAKING CHANGE: Header keys returned by `getAllHeaders` are converted
to lowercase. Accessing headers through non-lowercase keys will yield
`undefined`, even if the header in the request is in the same case. Use
lowercase keys, or use `getHeader`.
@seb-cr seb-cr requested a review from corinja December 11, 2023 13:18
Copy link
Member

@corinja corinja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@seb-cr seb-cr merged commit 141898e into beta Dec 11, 2023
@seb-cr seb-cr deleted the ENG-2735/lowercase-header-names branch December 11, 2023 16:16
@github-actions
Copy link

🎉 This PR is included in version 2.0.0-beta.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants