-
Notifications
You must be signed in to change notification settings - Fork 772
fix: work around immutable header guard
#1390
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
base: main
Are you sure you want to change the base?
Conversation
|
✅ Reviewed the changes: Fix for immutable header guard by cloning Response and Headers objects. Test cases updated accordingly. |
| cacheStatus: string | undefined, | ||
| retryAttempt: number | ||
| ) { | ||
| // Clone response and headers to work around `immutable` header guard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expensive operation, have to see if there are better ways to solve this, dont want to. be slowing down the fastest gateway xd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should work:
// Clone headers to work around `immutable` header guard
const kHeaders = Object.getOwnPropertySymbols(response).find((symbol) => symbol.toString() === 'Symbol(headers)');
Object.defineProperty(response, kHeaders, {
value: new Headers(response.headers),
writable: true,
enumerable: true,
configurable: true,
});do we like that better? the benefit is that we don't need to construct a new response, but it is making some unsafe assumptions about internals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option:
// Capture internal `getHeadersGuard` and `setHeadersGuard`
let getHeadersGuard, setHeadersGuard
const deleteProperty = Reflect.deleteProperty
Reflect.deleteProperty = function (...args) {
if (args[1] === 'getHeadersGuard') getHeadersGuard = args[0].getHeadersGuard
if (args[1] === 'setHeadersGuard') setHeadersGuard = args[0].setHeadersGuard
return deleteProperty.call(this, ...args)
}
// then
setHeadersGuard(response.headers, 'response')
Description
This PR fixes the
ResponseService.updateHeadersmethod to not try to mutate response headers, since it is forbidden by thefetchspec.Resolves #1389.
Motivation
Users who install incompatible (i.e. modern) versions of
@hono/node-serverwill end up with response errors when using Portkey.Type of Change
How Has This Been Tested?
Screenshots (if applicable)
Checklist
Related Issues
#1389