-
-
Notifications
You must be signed in to change notification settings - Fork 5
Setting headers on ctx.request
in middleware (request proxy bug?)
#7
Comments
Hi Tim, The shorthands are only for the So these should be equivalent: ctx.response.set("my-header", "my-value");
ctx.response.headers.set("my-header", "my-value");
ctx.request.get("some-header");
ctx.request.headers.get("some-header"); I decided against also proxying any |
As for the request headers being immutable: I haven't run into this before, perhaps incoming request headers are mutable and you have to init a new request using |
Thanks very much @gzuidhof 👍 I'm reconsidering my approach, as I think I'm building a footgun!
Indeed! (IIUC, headers on a Response received from It's possible to work around this like so: import { proxyRequest } from 'sunder/util/request'
// in middleware
ctx.request = proxyRequest(new Request(ctx.request.url, ctx.request))
ctx.request.headers.set('x-foo', 'bar') ...but this is probably a bad idea (better to set the specific request headers when constructing my sub-requests!) I wonder if it would be a good idea to remove Sunder's |
Hi! Thanks for your work on Sunder - loving it, learning plenty 🙏
I'm not sure if this issue is a bug, or user error…
I'm trying to add headers on the request object so that I can tweak the behaviour of sub-fetches (for caching and image resizing, etc).
I see that HeadersShorthands makes provision for this, but what I'm seeing is:
I'm expecting that:
ctx.request['x-foo-header']
will be handled by theget
trap on Sunder's proxied request, and returnctx.request.headers.get('x-foo-header')
ctx.request['x-foo-header'] = 'bar'
would similarly trigger theset
trap and mutaterequest.headers
So I guess there are two issues here:
HeadersShorthands
work as expected? I figure if theset
trap was getting hit as expected, then I'd see a type error (I didn't find any relevant tests)Regards, Tim
The text was updated successfully, but these errors were encountered: