@@ -28,6 +28,26 @@ interface ProxyFetch {
28
28
) : Promise < Response >
29
29
}
30
30
31
+ const buildRequestInitFromRequest = (
32
+ request : Request | undefined
33
+ ) : RequestInit & { duplex ?: 'half' } => {
34
+ if ( ! request ) {
35
+ return { }
36
+ }
37
+
38
+ const headers = new Headers ( request . headers )
39
+ hopByHopHeaders . forEach ( ( header ) => {
40
+ headers . delete ( header )
41
+ } )
42
+
43
+ return {
44
+ method : request . method ,
45
+ body : request . body ,
46
+ duplex : request . body ? 'half' : undefined ,
47
+ headers,
48
+ }
49
+ }
50
+
31
51
/**
32
52
* Fetch API wrapper for proxy.
33
53
* The parameters and return value are the same as for `fetch` (except for the proxy-specific options).
@@ -68,24 +88,8 @@ interface ProxyFetch {
68
88
export const proxy : ProxyFetch = async ( input , proxyInit ) => {
69
89
const { raw, ...requestInit } = proxyInit ?? { }
70
90
71
- const requestInitRaw : RequestInit & { duplex ?: 'half' } = raw
72
- ? {
73
- method : raw . method ,
74
- body : raw . body ,
75
- headers : raw . headers ,
76
- }
77
- : { }
78
- if ( requestInitRaw . body ) {
79
- requestInitRaw . duplex = 'half'
80
- }
81
- if ( requestInitRaw . headers ) {
82
- hopByHopHeaders . forEach ( ( header ) => {
83
- ; ( requestInitRaw . headers as Headers ) . delete ( header )
84
- } )
85
- }
86
-
87
91
const req = new Request ( input , {
88
- ...requestInitRaw ,
92
+ ...buildRequestInitFromRequest ( raw ) ,
89
93
...requestInit ,
90
94
} )
91
95
req . headers . delete ( 'accept-encoding' )
0 commit comments