Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support object returned by the response.getHeaders() when create Response #486

Closed
wants to merge 1 commit into from

Conversation

dead-horse
Copy link

koa use response.getHeaders() to get response headers, and the object returned by the response.getHeaders() method does not prototypically inherit from the JavaScript Object

@maxtruxa
Copy link
Member

maxtruxa commented May 2, 2018

Good catch. But wouldn't the canonical way to fix this be to just explicitly call hasOwnProperty?

I.e. replace

if (options.headers.hasOwnProperty(field)) {

with

if (Object.prototype.hasOwnProperty(options.headers, field)) {

You wouldn't even need the fallback if headers is not set (|| {}). Edit: NVM, passing null or undefined still fails, so that change is required and good.

@dead-horse dead-horse force-pushed the fix-header-not-object branch from b0a16a1 to 71a8736 Compare May 24, 2018 02:35
@dead-horse
Copy link
Author

@maxtruxa Object.prototype.hasOwnProperty.call(headers, field) is better to handle with Object.create(null) situation. please check this PR again :)

@dead-horse dead-horse force-pushed the fix-header-not-object branch from 71a8736 to cd5df6f Compare May 26, 2018 09:07
Copy link
Contributor

@mjsalinger mjsalinger left a comment

Choose a reason for hiding this comment

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

LGTM

@mjsalinger mjsalinger changed the base branch from master to dev August 7, 2018 11:49
@karladler
Copy link

Why is this not already merged?

@dead-horse dead-horse force-pushed the fix-header-not-object branch from cd5df6f to 8e72f30 Compare October 12, 2018 09:27
@dead-horse
Copy link
Author

I think this issue is already fixed in dev branch by 68ef835, when will it release?

@thomseddon thomseddon closed this Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants