@@ -35,27 +35,39 @@ export class IncomingMessage extends EventEmitter implements http.IncomingMessag
3535 public socket = new Socket ( true , true ) ;
3636
3737 #_originalUrlParsed: URL ;
38+ private parameterNames : string [ ] = [ ] ;
3839
3940 constructor (
4041 private req : uWS . HttpRequest ,
4142 private res : uWS . HttpResponse ,
42- private parameterNames : string [ ] ,
43- private app : Application
43+ private app : Application ,
44+ initialData ?: {
45+ headers ?: http . IncomingHttpHeaders ;
46+ url ?: string ;
47+ method ?: string ;
48+ body ?: any ;
49+ query ?: string ;
50+ remoteAddress ?: ArrayBuffer ;
51+ }
4452 ) {
4553 super ( ) ;
4654
47- this . req . forEach ( ( key , value ) => {
48- this . headers [ key ] = value ;
55+ this . headers = initialData ?. headers || { } ;
4956
50- // workaround: also consider 'referrer'
51- if ( key === "referer" ) { this . headers [ 'referrer' ] = value ; }
52- } ) ;
57+ if ( ! initialData ?. headers ) {
58+ this . req . forEach ( ( key , value ) => this . headers [ key ] = value ) ;
59+ }
5360
54- this . url = this . req . getUrl ( ) ;
55- this . method = this . req . getMethod ( ) . toUpperCase ( ) ;
61+ this . url = initialData ?. url || this . req . getUrl ( ) ;
62+ this . method = ( initialData ?. method || this . req . getMethod ( ) ) . toUpperCase ( ) ;
5663
57- this . _rawquery = this . req . getQuery ( ) ;
58- this . _remoteAddress = this . res . getRemoteAddressAsText ( ) ;
64+ this . _rawquery = initialData ?. query || this . req . getQuery ( ) ;
65+ this . _remoteAddress = initialData ?. remoteAddress || this . res . getRemoteAddressAsText ( ) ;
66+
67+ // workaround: also consider 'referrer'
68+ if ( this . headers [ 'referer' ] ) {
69+ this . headers [ 'referrer' ] = this . headers [ 'referer' ] ;
70+ }
5971
6072 if ( this . _rawquery ) {
6173 this . url += `?${ this . _rawquery } ` ;
0 commit comments