@@ -131,6 +131,70 @@ describe('HttpClient', function () {
131
131
request . headers . get ( 'Accept' ) ,
132
132
'application/json; charset=utf-8'
133
133
)
134
+ assert . strictEqual ( agent . keepAlive , false )
135
+ } )
136
+ } )
137
+
138
+ it ( 'can send a basic HTTP request with custom user-agent via client_options' , function ( ) {
139
+ const request = new HttpRequest ( 'GET' , '/echo' )
140
+ request . headers . set ( 'Foo' , 'Bar' )
141
+
142
+ const agent = new http . Agent ( )
143
+ agent . maxSockets = 1 // Only making 1 request.
144
+
145
+ const client = new HttpClient ( server . url ( ) , agent , null , {
146
+ 'user-agent' : 'test'
147
+ } )
148
+
149
+ return client . send ( request ) . then ( function ( response ) {
150
+ assert . strictEqual ( 200 , response . status )
151
+
152
+ const headers = JSON . parse ( response . body )
153
+ assert . strictEqual ( headers [ 'content-length' ] , '0' )
154
+ assert . strictEqual ( headers [ 'connection' ] , 'keep-alive' )
155
+ assert . strictEqual ( headers [ 'host' ] , server . host ( ) )
156
+ assert . strictEqual ( headers [ 'user-agent' ] , 'test' )
157
+
158
+ assert . strictEqual ( request . headers . get ( 'Foo' ) , 'Bar' )
159
+ assert . strictEqual ( agent . keepAlive , false )
160
+ assert . strictEqual (
161
+ request . headers . get ( 'Accept' ) ,
162
+ 'application/json; charset=utf-8'
163
+ )
164
+ } )
165
+ } )
166
+
167
+ it ( 'can send a basic HTTP request with keep-alive being set to true via client_options' , function ( ) {
168
+ const request = new HttpRequest ( 'GET' , '/echo' )
169
+ request . headers . set ( 'Foo' , 'Bar' )
170
+
171
+ const agent = new http . Agent ( )
172
+ agent . maxSockets = 1 // Only making 1 request.
173
+
174
+ const client = new HttpClient ( server . url ( ) , agent , null , {
175
+ 'keep-alive' : 'true' ,
176
+ } )
177
+
178
+ return client . send ( request ) . then ( function ( response ) {
179
+ assert . strictEqual ( 200 , response . status )
180
+
181
+ const headers = JSON . parse ( response . body )
182
+ assert . strictEqual ( headers [ 'content-length' ] , '0' )
183
+ assert . strictEqual ( headers [ 'connection' ] , 'keep-alive' )
184
+ assert . strictEqual ( headers [ 'host' ] , server . host ( ) )
185
+
186
+ const regex = / ^ s e l e n i u m \/ .* \( j s ( w i n d o w s | m a c | l i n u x ) \) $ /
187
+ assert . ok (
188
+ regex . test ( headers [ 'user-agent' ] ) ,
189
+ `${ headers [ 'user-agent' ] } does not match ${ regex } `
190
+ )
191
+
192
+ assert . strictEqual ( request . headers . get ( 'Foo' ) , 'Bar' )
193
+ assert . strictEqual ( agent . keepAlive , true )
194
+ assert . strictEqual (
195
+ request . headers . get ( 'Accept' ) ,
196
+ 'application/json; charset=utf-8'
197
+ )
134
198
} )
135
199
} )
136
200
0 commit comments