@@ -42,14 +42,7 @@ export class Request extends GlobalRequest {
4242 }
4343}
4444
45- export type IncomingMessageWithWrapBodyStream = IncomingMessage & { [ wrapBodyStream ] : boolean }
46- export const wrapBodyStream = Symbol ( 'wrapBodyStream' )
47- const newRequestFromIncoming = (
48- method : string ,
49- url : string ,
50- incoming : IncomingMessage | Http2ServerRequest ,
51- abortController : AbortController
52- ) : Request => {
45+ const newHeadersFromIncoming = ( incoming : IncomingMessage | Http2ServerRequest ) => {
5346 const headerRecord : [ string , string ] [ ] = [ ]
5447 const rawHeaders = incoming . rawHeaders
5548 for ( let i = 0 ; i < rawHeaders . length ; i += 2 ) {
@@ -58,10 +51,21 @@ const newRequestFromIncoming = (
5851 headerRecord . push ( [ key , value ] )
5952 }
6053 }
54+ return new Headers ( headerRecord )
55+ }
6156
57+ export type IncomingMessageWithWrapBodyStream = IncomingMessage & { [ wrapBodyStream ] : boolean }
58+ export const wrapBodyStream = Symbol ( 'wrapBodyStream' )
59+ const newRequestFromIncoming = (
60+ method : string ,
61+ url : string ,
62+ headers : Headers ,
63+ incoming : IncomingMessage | Http2ServerRequest ,
64+ abortController : AbortController
65+ ) : Request => {
6266 const init = {
6367 method : method ,
64- headers : headerRecord ,
68+ headers,
6569 signal : abortController . signal ,
6670 } as RequestInit
6771
@@ -116,6 +120,7 @@ const getRequestCache = Symbol('getRequestCache')
116120const requestCache = Symbol ( 'requestCache' )
117121const incomingKey = Symbol ( 'incomingKey' )
118122const urlKey = Symbol ( 'urlKey' )
123+ const headersKey = Symbol ( 'headersKey' )
119124export const abortControllerKey = Symbol ( 'abortControllerKey' )
120125export const getAbortController = Symbol ( 'getAbortController' )
121126
@@ -128,6 +133,10 @@ const requestPrototype: Record<string | symbol, any> = {
128133 return this [ urlKey ]
129134 } ,
130135
136+ get headers ( ) {
137+ return ( this [ headersKey ] ||= newHeadersFromIncoming ( this [ incomingKey ] ) )
138+ } ,
139+
131140 [ getAbortController ] ( ) {
132141 this [ getRequestCache ] ( )
133142 return this [ abortControllerKey ]
@@ -138,6 +147,7 @@ const requestPrototype: Record<string | symbol, any> = {
138147 return ( this [ requestCache ] ||= newRequestFromIncoming (
139148 this . method ,
140149 this [ urlKey ] ,
150+ this . headers ,
141151 this [ incomingKey ] ,
142152 this [ abortControllerKey ]
143153 ) )
@@ -149,7 +159,6 @@ const requestPrototype: Record<string | symbol, any> = {
149159 'cache' ,
150160 'credentials' ,
151161 'destination' ,
152- 'headers' ,
153162 'integrity' ,
154163 'mode' ,
155164 'redirect' ,
0 commit comments