@@ -30,11 +30,6 @@ describe(`Console's send request`, () => {
3030 beforeEach ( ( ) => {
3131 sandbox = sinon . createSandbox ( ) ;
3232 stub = sandbox . stub ( http , 'request' ) . callsFake ( ( ) => {
33- fakeRequest = {
34- abort : sinon . stub ( ) ,
35- on ( ) { } ,
36- once ( ) { } ,
37- } as any ;
3833 return fakeRequest ;
3934 } ) ;
4035 } ) ;
@@ -45,6 +40,11 @@ describe(`Console's send request`, () => {
4540 } ) ;
4641
4742 it ( 'correctly implements timeout and abort mechanism' , async ( ) => {
43+ fakeRequest = {
44+ abort : sinon . stub ( ) ,
45+ on ( ) { } ,
46+ once ( ) { } ,
47+ } as any ;
4848 try {
4949 await proxyRequest ( {
5050 agent : null as any ,
@@ -60,4 +60,55 @@ describe(`Console's send request`, () => {
6060 expect ( ( fakeRequest . abort as sinon . SinonStub ) . calledOnce ) . toBe ( true ) ;
6161 }
6262 } ) ;
63+
64+ it ( 'correctly sets the "host" header entry' , async ( ) => {
65+ fakeRequest = {
66+ abort : sinon . stub ( ) ,
67+ on ( ) { } ,
68+ once ( event : string , fn : any ) {
69+ if ( event === 'response' ) {
70+ return fn ( 'done' ) ;
71+ }
72+ } ,
73+ } as any ;
74+
75+ // Don't set a host header this time
76+ const result1 = await proxyRequest ( {
77+ agent : null as any ,
78+ headers : { } ,
79+ method : 'get' ,
80+ payload : null as any ,
81+ timeout : 30000 ,
82+ uri : new URL ( 'http://noone.nowhere.none' ) ,
83+ } ) ;
84+
85+ expect ( result1 ) . toEqual ( 'done' ) ;
86+
87+ const [ httpRequestOptions1 ] = stub . firstCall . args ;
88+
89+ expect ( ( httpRequestOptions1 as any ) . headers ) . toEqual ( {
90+ 'content-type' : 'application/json' ,
91+ host : 'noone.nowhere.none' , // Defaults to the provided host name
92+ 'transfer-encoding' : 'chunked' ,
93+ } ) ;
94+
95+ // Set a host header
96+ const result2 = await proxyRequest ( {
97+ agent : null as any ,
98+ headers : { Host : 'myhost' } ,
99+ method : 'get' ,
100+ payload : null as any ,
101+ timeout : 30000 ,
102+ uri : new URL ( 'http://noone.nowhere.none' ) ,
103+ } ) ;
104+
105+ expect ( result2 ) . toEqual ( 'done' ) ;
106+
107+ const [ httpRequestOptions2 ] = stub . secondCall . args ;
108+ expect ( ( httpRequestOptions2 as any ) . headers ) . toEqual ( {
109+ 'content-type' : 'application/json' ,
110+ Host : 'myhost' , // Uses provided host name
111+ 'transfer-encoding' : 'chunked' ,
112+ } ) ;
113+ } ) ;
63114} ) ;
0 commit comments