File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ function Fetch(url, opts) {
7474 headers . set ( 'user-agent' , 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)' ) ;
7575 }
7676
77- if ( ! headers . has ( 'connection' ) ) {
77+ if ( ! headers . has ( 'connection' ) && ! options . agent ) {
7878 headers . set ( 'connection' , 'close' ) ;
7979 }
8080
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ function TestServer() {
1515 this . server . on ( 'error' , function ( err ) {
1616 console . log ( err . stack ) ;
1717 } ) ;
18+ this . server . on ( 'connection' , function ( socket ) {
19+ socket . setTimeout ( 1500 ) ;
20+ } ) ;
1821}
1922
2023TestServer . prototype . start = function ( cb ) {
Original file line number Diff line number Diff line change @@ -950,6 +950,20 @@ describe('node-fetch', function() {
950950 } ) ;
951951 } ) ;
952952
953+ it ( 'should send request with connection keep-alive if agent is provided' , function ( ) {
954+ url = base + '/inspect' ;
955+ opts = {
956+ agent : new http . Agent ( {
957+ keepAlive : true
958+ } )
959+ } ;
960+ return fetch ( url , opts ) . then ( function ( res ) {
961+ return res . json ( ) ;
962+ } ) . then ( function ( res ) {
963+ expect ( res . headers [ 'connection' ] ) . to . equal ( 'keep-alive' ) ;
964+ } ) ;
965+ } ) ;
966+
953967 it ( 'should ignore unsupported attributes while reading headers' , function ( ) {
954968 var FakeHeader = function ( ) { } ;
955969 // prototypes are ignored
You can’t perform that action at this time.
0 commit comments