-
-
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
A way to completly overwrite response from middleware after next() #960
Comments
Hi @TorbjornHoltmon ! I have ideas about this "middleware matter". I'll let you know later. |
Hi @TorbjornHoltmon ! I've created PR #970 . With this PR, you can do it by putting app.use('*', async (c, next) => {
await next()
c.res = undefined
c.res = new Response('New Response')
}) This way does not include breaking changes and makes it possible what you want to do. |
I think we can close this issue. Thanks. |
Hi, can you document this feature ? @yusukebe I think this is really helpful for custom middleware. I just found the feature was implemented here. |
Hi @fzn0x Created the issue honojs/website#317 on the website repo. We'll do that. |
This is a very niche issue.
We use Hono for many things, including our Cloudflare workers' proxy.
The proxy sits on top of our domain and routes traffic to different workers and other external servers.
When you proxy a request from a worker, the response that Hono gets is a fetch response, and you cannot change headers.
When we use middleware in our proxy, there is no way for us to re-write the response since ´contex.res´ has a
set
that manipulates the headers.https://github.com/honojs/hono/blob/fea78f29bd681350ce61dd71b33042aa6ec7db5c/src/context.ts#LL101-L110C4
Not many people will have this issue, but we could really use some type of overwrite on the response so that we can write middleware that does something like this:
If only the
set
did not change headers we could have used thatMaybe this is something that should be contained in its own world. "hono/proxy". Which is meant to handle things as a proxy and not api.
The text was updated successfully, but these errors were encountered: