@@ -167,6 +167,41 @@ describe('HttpProxyAgent', function () {
167
167
done ( ) ;
168
168
} ) ;
169
169
} ) ;
170
+ it ( 'should send the "Proxy-Authorization" request header' , function ( done ) {
171
+ // set a proxy authentication function for this test
172
+ proxy . authenticate = function ( req , fn ) {
173
+ // username:password is "foo:bar"
174
+ fn ( null , req . headers [ 'proxy-authorization' ] == 'Basic Zm9vOmJhcg==' ) ;
175
+ } ;
176
+
177
+ // set HTTP "request" event handler for this test
178
+ server . once ( 'request' , function ( req , res ) {
179
+ res . end ( JSON . stringify ( req . headers ) ) ;
180
+ } ) ;
181
+
182
+ var proxyUri = process . env . HTTP_PROXY || process . env . http_proxy || 'http://127.0.0.1:' + proxyPort ;
183
+ var proxyOpts = url . parse ( proxyUri ) ;
184
+ proxyOpts . auth = 'foo:bar' ;
185
+ var agent = new HttpProxyAgent ( proxyOpts ) ;
186
+
187
+ var opts = url . parse ( 'http://127.0.0.1:' + serverPort ) ;
188
+ opts . agent = agent ;
189
+
190
+ http . get ( opts , function ( res ) {
191
+ var data = '' ;
192
+ res . setEncoding ( 'utf8' ) ;
193
+ res . on ( 'data' , function ( b ) {
194
+ data += b ;
195
+ } ) ;
196
+ res . on ( 'end' , function ( ) {
197
+ data = JSON . parse ( data ) ;
198
+ assert . equal ( '127.0.0.1:' + serverPort , data . host ) ;
199
+ assert ( 'via' in data ) ;
200
+ delete proxy . authenticate ;
201
+ done ( ) ;
202
+ } ) ;
203
+ } ) ;
204
+ } ) ;
170
205
} ) ;
171
206
172
207
} ) ;
0 commit comments