-
-
Notifications
You must be signed in to change notification settings - Fork 666
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
fix(proxy): remove spread operator from Request
and Response
classes
#3928
fix(proxy): remove spread operator from Request
and Response
classes
#3928
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3928 +/- ##
==========================================
- Coverage 91.32% 91.29% -0.04%
==========================================
Files 168 168
Lines 10689 10774 +85
Branches 3056 3101 +45
==========================================
+ Hits 9762 9836 +74
- Misses 926 937 +11
Partials 1 1 ☔ View full report in Codecov by Sentry. |
Hi @BarryThePenguin. Thank you. Please do not modify the diff --git a/src/helper/proxy/index.ts b/src/helper/proxy/index.ts
index 4c010a2d..93a7543b 100644
--- a/src/helper/proxy/index.ts
+++ b/src/helper/proxy/index.ts
@@ -49,13 +49,13 @@ const buildRequestInitFromRequest = (
}
}
-const preprocessRequestInit = (requestInit: RequestInit): RequestInit => {
+const preprocessRequestInit = (requestInit: Readonly<ProxyRequestInit>): RequestInit => {
if (
!requestInit.headers ||
Array.isArray(requestInit.headers) ||
requestInit.headers instanceof Headers
) {
- return requestInit
+ return requestInit as RequestInit
}
const headers = new Headers()
@@ -67,8 +67,10 @@ const preprocessRequestInit = (requestInit: RequestInit): RequestInit => {
headers.set(key, value)
}
}
- requestInit.headers = headers
- return requestInit
+ return {
+ ...requestInit,
+ headers,
+ }
}
/**
@@ -111,7 +113,7 @@ const preprocessRequestInit = (requestInit: RequestInit): RequestInit => {
export const proxy: ProxyFetch = async (input, proxyInit = {}) => {
const req = new Request(input, {
...buildRequestInitFromRequest(proxyInit.raw),
- ...preprocessRequestInit(proxyInit as RequestInit),
+ ...preprocessRequestInit(proxyInit),
})
req.headers.delete('accept-encoding')
Also, if possible, since the changes to src/helper/proxy/index.ts are different from the following, it would be helpful if you could include only one purpose in one PR.
|
I was trying to avoid using the spread operator on hono/src/helper/proxy/index.ts Line 113 in 6ae0213
As the current API for app.get('/proxy/:path', (c) => {
return proxy(`http://${originServer}/${c.req.param('path')}`, c.req.raw)
}) Though I'm not sure if this is intentional or not. I'll revert the changes to |
Hi @BarryThePenguin. Thank you for getting back to me. I see, as you say, it would be better if the following code (although it is not the recommended way to use it) processed app.get(‘/proxy/:path’, (c) => {
return proxy(`http://${originServer}/${c.req.param(‘path’)}`, c.req.raw)
}) Let's discuss it in another PR. |
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.
LGTM!
Thank you. Looks good. I'll merge this now. |
Removes usage of the spread operator (
...
) onRequest
andResponse
classesFollow-up from #3927