-
-
Notifications
You must be signed in to change notification settings - Fork 634
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
When using new Response
as a return value, the headers set by c.header()
are lost in the actual response.
#2681
Comments
@syfxlin, I saw that the |
I divided the problem into two parts: set res(_res: Response | undefined) {
this.#isFresh = false
if (this.#res && _res) {
const headers = this.#res.headers
for (const [k, v] of headers.entries()) {
_res.headers.set(k, v)
}
const setCookieHeader = headers.get('set-cookie')
if (setCookieHeader) {
_res.headers.set('set-cookie', setCookieHeader)
}
}
this.#res = _res
this.finalized = true
} I am waiting now that the problem is resolved 🍡 |
Hi @syfxlin This is not a bug. If it returns raw |
Hi @yusukebe, sometimes, we may not be able to return a response using |
The same issue was discussed in #1526 Some say that a context header should be added to the Regarding |
Hi @yusukebe, thanks for your answer, I think it's acceptable not to add headers implicitly, so close this issue, it would be nice if you could state this in the documentation to avoid confusion. |
What version of Hono are you using?
4.3.7
What runtime/platform is your app running on?
Node.js
What steps can reproduce the bug?
When using
new Response
as a return value, the headers set byc.header()
are lost in the actual response. If the response is returned using c.text, the headers will appear normally in the actual response.pnpm init
pnpm i hono @hono/node-server
node index.mjs
curl http://localhost:3000 -v
What is the expected behavior?
The actual response should contain all the set headers.
What do you see instead?
c.header
before creating the response, it is stored inc.#header
, See: https://github.com/honojs/hono/blob/main/src/context.ts#L297c.res
, See: https://github.com/honojs/hono/blob/main/src/compose.ts#L60c.#res.headers
will then be copied into the response returned from the middleware (_res), See: https://github.com/honojs/hono/blob/main/src/context.ts#L196-L212Additional information
No response
The text was updated successfully, but these errors were encountered: