Skip to content

Conversation

@usualoma
Copy link
Member

I understand that res.headers is not necessarily an instance of Headers when combined with another framework. In this kind of environment, I think it is safe to assume that it will return either HeadersInit, null, or undefined.

I think it would be better to keep the code from v1.13.3 as it is for processing the contents of the header, and to call new Headers() if it is not Headers. The reason is as follows

  • The header name is case-insensitive, so you cannot compare it directly using an Object key, such as === 'set-cookie'
  • The value “ should be preserved without being deleted

@usualoma
Copy link
Member Author

Hi @mjad218, I'd like to hear your opinion.

I would like to summarize this matter with this code.

However, the following changes you have made will not be reflected in this code.
6a6be4f

In Node, if an application passes a value like undefined to the constructor of Headers, the following result will be obtained.

> new Headers({"a":undefined})
Headers { a: 'undefined' }

Does it actually happen that NestJS specifies undefined as the value for “headers that should not be sent”?

@ghost
Copy link

ghost commented Oct 31, 2024

@usualoma Sounds good. new Headers(object) will map objects to headers instance. So, I think your solution is good.

and new Headers(null or undefined) works and does not throw errors.

@usualoma
Copy link
Member Author

@mjad218 Thanks for the reply!

@yusukebe How about this approach?

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

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

LGTM!

@yusukebe
Copy link
Member

yusukebe commented Nov 4, 2024

Thanks @usualoma !

This is simple, and it can handle the problems. Looks good!

@yusukebe yusukebe merged commit 9327d9c into honojs:main Nov 4, 2024
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.

2 participants