@@ -175,6 +175,49 @@ describe('request', function () {
175
175
. then ( done , done ) ;
176
176
} ) ;
177
177
178
+ it ( 'agent can be used to set default headers' , function ( done ) {
179
+ var agent = request . agent ( 'https://httpbin.org' ) ;
180
+ agent . set ( "Header-Name" , "header_value" ) ;
181
+
182
+ agent
183
+ . get ( '/headers' )
184
+ . then ( function ( res ) {
185
+ res . should . have . status ( 200 ) ;
186
+ res . body . headers . should . have . property ( 'Header-Name' ) . that . equals ( "header_value" ) ;
187
+ agent . close ( ) ;
188
+ } )
189
+ . then ( done , done ) ;
190
+ } ) ;
191
+
192
+ it ( 'agent can be used to set default bearer authentication' , function ( done ) {
193
+ var agent = request . agent ( 'https://httpbin.org' ) ;
194
+ agent . set ( "Authorization" , "Bearer test_bearer" ) ;
195
+
196
+ agent
197
+ . get ( '/bearer' )
198
+ . then ( function ( res ) {
199
+ res . should . have . status ( 200 ) ;
200
+ res . should . be . json ;
201
+ res . body . should . have . property ( 'authenticated' ) . that . equals ( true ) ;
202
+ res . body . should . have . property ( 'token' ) . that . equals ( "test_bearer" ) ;
203
+ agent . close ( ) ;
204
+ } )
205
+ . then ( done , done ) ;
206
+ } ) ;
207
+
208
+ it ( 'agent can be used to set default basic authentication' , function ( done ) {
209
+ var agent = request . agent ( 'https://httpbin.org' ) ;
210
+ agent . auth ( "user" , "passwd" ) ;
211
+
212
+ agent
213
+ . get ( '/basic-auth/user/passwd' )
214
+ . then ( function ( res ) {
215
+ res . should . have . status ( 200 ) ;
216
+ agent . close ( ) ;
217
+ } )
218
+ . then ( done , done ) ;
219
+ } ) ;
220
+
178
221
it ( 'automatically closes the server down once done with it' , function ( done ) {
179
222
var server = require ( 'http' ) . createServer ( function ( req , res ) {
180
223
res . writeHeader ( 200 , { 'content-type' : 'text/plain' } ) ;
0 commit comments