@@ -129,79 +129,81 @@ describe("#createProxyServer.web() using own http server", () => {
129129 . end ( ) ;
130130 } ) ) ;
131131
132- it . skipIf ( ( ) => process . env . FORCE_UNDICI_PATH === "true" ) ( "should detect a proxyReq event and modify headers" , ( ) => new Promise < void > ( done => {
133- const proxy = httpProxy . createProxyServer ( {
134- target : address ( 8080 ) ,
135- } ) ;
132+ it . skipIf ( ( ) => process . env . FORCE_FETCH_PATH
133+ === "true" ) ( "should detect a proxyReq event and modify headers" , ( ) => new Promise < void > ( done => {
134+ const proxy = httpProxy . createProxyServer ( {
135+ target : address ( 8080 ) ,
136+ } ) ;
136137
137- proxy . on ( "proxyReq" , ( proxyReq , _req , _res , _options ) => {
138- proxyReq . setHeader ( "X-Special-Proxy-Header" , "foobar" ) ;
139- } ) ;
138+ proxy . on ( "proxyReq" , ( proxyReq , _req , _res , _options ) => {
139+ proxyReq . setHeader ( "X-Special-Proxy-Header" , "foobar" ) ;
140+ } ) ;
140141
141- function requestHandler ( req : http . IncomingMessage , res : http . ServerResponse ) {
142- proxy . web ( req , res ) ;
143- }
142+ function requestHandler ( req : http . IncomingMessage , res : http . ServerResponse ) {
143+ proxy . web ( req , res ) ;
144+ }
144145
145- const proxyServer = http . createServer ( requestHandler ) ;
146+ const proxyServer = http . createServer ( requestHandler ) ;
146147
147- const source = http . createServer ( ( req , res ) => {
148- res . end ( ) ;
149- source . close ( ) ;
150- proxyServer . close ( ) ;
151- expect ( req . headers [ "x-special-proxy-header" ] ) . toEqual ( "foobar" ) ;
152- done ( ) ;
153- } ) ;
148+ const source = http . createServer ( ( req , res ) => {
149+ res . end ( ) ;
150+ source . close ( ) ;
151+ proxyServer . close ( ) ;
152+ expect ( req . headers [ "x-special-proxy-header" ] ) . toEqual ( "foobar" ) ;
153+ done ( ) ;
154+ } ) ;
154155
155- proxyServer . listen ( ports [ "8081" ] ) ;
156- source . listen ( ports [ "8080" ] ) ;
156+ proxyServer . listen ( ports [ "8081" ] ) ;
157+ source . listen ( ports [ "8080" ] ) ;
157158
158- http . request ( address ( 8081 ) , ( ) => { } ) . end ( ) ;
159- } ) ) ;
159+ http . request ( address ( 8081 ) , ( ) => { } ) . end ( ) ;
160+ } ) ) ;
160161
161- it . skipIf ( ( ) => process . env . FORCE_UNDICI_PATH === "true" ) ( 'should skip proxyReq event when handling a request with header "expect: 100-continue" [https://www.npmjs.com/advisories/1486]' , ( ) => new Promise < void > ( done => {
162- const proxy = httpProxy . createProxyServer ( {
163- target : address ( 8080 ) ,
164- } ) ;
162+ it . skipIf ( ( ) => process . env . FORCE_FETCH_PATH
163+ === "true" ) ( 'should skip proxyReq event when handling a request with header "expect: 100-continue" [https://www.npmjs.com/advisories/1486]' , ( ) => new Promise < void > ( done => {
164+ const proxy = httpProxy . createProxyServer ( {
165+ target : address ( 8080 ) ,
166+ } ) ;
165167
166- proxy . on ( "proxyReq" , ( proxyReq , _req , _res , _options ) => {
167- proxyReq . setHeader ( "X-Special-Proxy-Header" , "foobar" ) ;
168- } ) ;
168+ proxy . on ( "proxyReq" , ( proxyReq , _req , _res , _options ) => {
169+ proxyReq . setHeader ( "X-Special-Proxy-Header" , "foobar" ) ;
170+ } ) ;
169171
170- function requestHandler ( req : http . IncomingMessage , res : http . ServerResponse ) {
171- proxy . web ( req , res ) ;
172- }
172+ function requestHandler ( req : http . IncomingMessage , res : http . ServerResponse ) {
173+ proxy . web ( req , res ) ;
174+ }
173175
174- const proxyServer = http . createServer ( requestHandler ) ;
176+ const proxyServer = http . createServer ( requestHandler ) ;
175177
176- const source = http . createServer ( ( req , res ) => {
177- res . end ( ) ;
178- source . close ( ) ;
179- proxyServer . close ( ) ;
180- expect ( req . headers [ "x-special-proxy-header" ] ) . not . toEqual ( "foobar" ) ;
181- done ( ) ;
182- } ) ;
178+ const source = http . createServer ( ( req , res ) => {
179+ res . end ( ) ;
180+ source . close ( ) ;
181+ proxyServer . close ( ) ;
182+ expect ( req . headers [ "x-special-proxy-header" ] ) . not . toEqual ( "foobar" ) ;
183+ done ( ) ;
184+ } ) ;
183185
184- proxyServer . listen ( ports [ "8081" ] ) ;
185- source . listen ( ports [ "8080" ] ) ;
186+ proxyServer . listen ( ports [ "8081" ] ) ;
187+ source . listen ( ports [ "8080" ] ) ;
186188
187- const postData = "" . padStart ( 1025 , "x" ) ;
189+ const postData = "" . padStart ( 1025 , "x" ) ;
188190
189- const postOptions = {
190- hostname : "127.0.0.1" ,
191- port : ports [ "8081" ] ,
192- path : "/" ,
193- method : "POST" ,
194- headers : {
195- "Content-Type" : "application/x-www-form-urlencoded" ,
196- "Content-Length" : Buffer . byteLength ( postData ) ,
197- expect : "100-continue" ,
198- } ,
199- } ;
191+ const postOptions = {
192+ hostname : "127.0.0.1" ,
193+ port : ports [ "8081" ] ,
194+ path : "/" ,
195+ method : "POST" ,
196+ headers : {
197+ "Content-Type" : "application/x-www-form-urlencoded" ,
198+ "Content-Length" : Buffer . byteLength ( postData ) ,
199+ expect : "100-continue" ,
200+ } ,
201+ } ;
200202
201- const req = http . request ( postOptions , ( ) => { } ) ;
202- req . write ( postData ) ;
203- req . end ( ) ;
204- } ) ) ;
203+ const req = http . request ( postOptions , ( ) => { } ) ;
204+ req . write ( postData ) ;
205+ req . end ( ) ;
206+ } ) ) ;
205207
206208 it ( "should proxy the request and handle error via callback" , ( ) => new Promise < void > ( done => {
207209 const proxy = httpProxy . createProxyServer ( {
@@ -390,85 +392,87 @@ describe("#createProxyServer.web() using own http server", () => {
390392 req . end ( ) ;
391393 } ) ) ;
392394
393- it . skipIf ( ( ) => process . env . FORCE_UNDICI_PATH === "true" ) ( "should proxy the request and provide a proxyRes event with the request and response parameters" , ( ) => new Promise < void > ( done => {
394- const proxy = httpProxy . createProxyServer ( {
395- target : address ( 8080 ) ,
396- } ) ;
397-
398- function requestHandler ( req : http . IncomingMessage , res : http . ServerResponse ) {
399- proxy . once ( "proxyRes" , ( proxyRes , pReq , pRes ) => {
400- source . close ( ) ;
401- proxyServer . close ( ) ;
402- expect ( proxyRes != null ) . toBe ( true ) ;
403- expect ( pReq ) . toEqual ( req ) ;
404- expect ( pRes ) . toEqual ( res ) ;
405- done ( ) ;
395+ it . skipIf ( ( ) => process . env . FORCE_FETCH_PATH
396+ === "true" ) ( "should proxy the request and provide a proxyRes event with the request and response parameters" , ( ) => new Promise < void > ( done => {
397+ const proxy = httpProxy . createProxyServer ( {
398+ target : address ( 8080 ) ,
406399 } ) ;
407400
408- proxy . web ( req , res ) ;
409- }
401+ function requestHandler ( req : http . IncomingMessage , res : http . ServerResponse ) {
402+ proxy . once ( "proxyRes" , ( proxyRes , pReq , pRes ) => {
403+ source . close ( ) ;
404+ proxyServer . close ( ) ;
405+ expect ( proxyRes != null ) . toBe ( true ) ;
406+ expect ( pReq ) . toEqual ( req ) ;
407+ expect ( pRes ) . toEqual ( res ) ;
408+ done ( ) ;
409+ } ) ;
410410
411- const proxyServer = http . createServer ( requestHandler ) ;
411+ proxy . web ( req , res ) ;
412+ }
412413
413- const source = http . createServer ( ( _req , res ) => {
414- res . end ( "Response" ) ;
415- } ) ;
414+ const proxyServer = http . createServer ( requestHandler ) ;
416415
417- proxyServer . listen ( port ( 8086 ) ) ;
418- source . listen ( port ( 8080 ) ) ;
419- http . request ( address ( 8086 ) , ( ) => { } ) . end ( ) ;
420- } ) ) ;
416+ const source = http . createServer ( ( _req , res ) => {
417+ res . end ( "Response" ) ;
418+ } ) ;
421419
422- it . skipIf ( ( ) => process . env . FORCE_UNDICI_PATH === "true" ) ( "should proxy the request and provide and respond to manual user response when using modifyResponse" , ( ) => new Promise ( done => {
423- const proxy = httpProxy . createProxyServer ( {
424- target : address ( 8080 ) ,
425- selfHandleResponse : true ,
426- } ) ;
420+ proxyServer . listen ( port ( 8086 ) ) ;
421+ source . listen ( port ( 8080 ) ) ;
422+ http . request ( address ( 8086 ) , ( ) => { } ) . end ( ) ;
423+ } ) ) ;
427424
428- function requestHandler ( req : http . IncomingMessage , res : http . ServerResponse ) {
429- proxy . once ( "proxyRes" , ( proxyRes , _pReq , pRes ) => {
430- proxyRes . pipe (
431- concat ( ( body ) => {
432- expect ( body . toString ( "utf8" ) ) . toEqual ( "Response" ) ;
433- pRes . end ( Buffer . from ( "my-custom-response" ) ) ;
434- } ) ,
435- ) ;
425+ it . skipIf ( ( ) => process . env . FORCE_FETCH_PATH
426+ === "true" ) ( "should proxy the request and provide and respond to manual user response when using modifyResponse" , ( ) => new Promise ( done => {
427+ const proxy = httpProxy . createProxyServer ( {
428+ target : address ( 8080 ) ,
429+ selfHandleResponse : true ,
436430 } ) ;
437431
438- proxy . web ( req , res ) ;
439- }
432+ function requestHandler ( req : http . IncomingMessage , res : http . ServerResponse ) {
433+ proxy . once ( "proxyRes" , ( proxyRes , _pReq , pRes ) => {
434+ proxyRes . pipe (
435+ concat ( ( body ) => {
436+ expect ( body . toString ( "utf8" ) ) . toEqual ( "Response" ) ;
437+ pRes . end ( Buffer . from ( "my-custom-response" ) ) ;
438+ } ) ,
439+ ) ;
440+ } ) ;
440441
441- const proxyServer = http . createServer ( requestHandler ) ;
442+ proxy . web ( req , res ) ;
443+ }
442444
443- const source = http . createServer ( ( _req , res ) => {
444- res . end ( "Response" ) ;
445- } ) ;
445+ const proxyServer = http . createServer ( requestHandler ) ;
446446
447- async . parallel (
448- [
449- ( next ) => proxyServer . listen ( port ( 8086 ) , next ) ,
450- ( next ) => source . listen ( port ( 8080 ) , next ) ,
451- ] ,
452- ( _err ) => {
453- http
454- . get ( address ( 8086 ) , ( res ) => {
455- res . pipe (
456- concat ( ( body ) => {
457- expect ( body . toString ( "utf8" ) ) . toEqual ( "my-custom-response" ) ;
458- source . close ( ) ;
459- proxyServer . close ( ) ;
460- done ( undefined ) ;
461- } ) ,
462- ) ;
463- } )
464- . once ( "error" , ( err ) => {
465- source . close ( ) ;
466- proxyServer . close ( ) ;
467- done ( err ) ;
468- } ) ;
469- } ,
470- ) ;
471- } ) ) ;
447+ const source = http . createServer ( ( _req , res ) => {
448+ res . end ( "Response" ) ;
449+ } ) ;
450+
451+ async . parallel (
452+ [
453+ ( next ) => proxyServer . listen ( port ( 8086 ) , next ) ,
454+ ( next ) => source . listen ( port ( 8080 ) , next ) ,
455+ ] ,
456+ ( _err ) => {
457+ http
458+ . get ( address ( 8086 ) , ( res ) => {
459+ res . pipe (
460+ concat ( ( body ) => {
461+ expect ( body . toString ( "utf8" ) ) . toEqual ( "my-custom-response" ) ;
462+ source . close ( ) ;
463+ proxyServer . close ( ) ;
464+ done ( undefined ) ;
465+ } ) ,
466+ ) ;
467+ } )
468+ . once ( "error" , ( err ) => {
469+ source . close ( ) ;
470+ proxyServer . close ( ) ;
471+ done ( err ) ;
472+ } ) ;
473+ } ,
474+ ) ;
475+ } ) ) ;
472476
473477 it ( "should proxy the request and handle changeOrigin option" , ( ) => new Promise < void > ( done => {
474478 const proxy = httpProxy
0 commit comments