@@ -26,35 +26,28 @@ function defaultPromiseFactory(resolver) {
26
26
return new Promise ( resolver ) ;
27
27
}
28
28
29
- // Prevent Cookie & Authorization Headers from being forwarded
30
- // when the URL redirects to another domain (information leak) #137
29
+ // Prevent Cookie & Authorization Headers from being forwarded
30
+ // when the URL redirects to another domain (information leak) #137
31
31
function sanitizeHeaders ( options ) {
32
-
33
32
const HEADERS_TO_IGNORE = [ "cookie" , "authorization" ] ;
34
33
35
- const urlObject = url . parse ( options . url )
34
+ const urlObject = url . parse ( options . url || options . uri ) ;
36
35
const queryObject = querystring . parse ( urlObject . query ) ;
37
-
38
- const hasExternalLink = Object . keys ( queryObject ) . reduce ( function ( acc , cur ) {
39
-
40
- let qUrl = url . parse ( queryObject [ cur ] ) ;
36
+
37
+ const hasExternalLink = Object . keys ( queryObject ) . some ( function ( queryParam ) {
38
+ const qUrl = url . parse ( queryObject [ queryParam ] ) ;
41
39
42
40
// external link if protocol || host || port is different
43
- if ( ! ! qUrl . host && ( qUrl . protocol !== urlObject . protocol || qUrl . host !== urlObject . host || qUrl . port !== urlObject . port ) ) {
44
- acc = true ;
45
- }
46
-
47
- return acc ;
41
+ return ! ! qUrl . host && ( qUrl . protocol !== urlObject . protocol || qUrl . host !== urlObject . host || qUrl . port !== urlObject . port ) ;
42
+ } ) ;
48
43
49
- } , false ) ;
44
+ if ( hasExternalLink && options . hasOwnProperty ( "headers" ) && typeof ( options . headers ) === "object" ) {
50
45
51
- if ( hasExternalLink && options . hasOwnProperty ( "headers" ) && typeof ( options . headers ) === "object" ) {
52
-
53
46
// if External Link: remove Cookie and Authorization from Headers
54
- Object . keys ( options . headers ) . filter ( function ( key ) {
55
- return HEADERS_TO_IGNORE . includes ( key . toLowerCase ( ) )
56
- } ) . map ( function ( key ) {
57
- return delete options . headers [ key ]
47
+ Object . keys ( options . headers ) . filter ( function ( key ) {
48
+ return HEADERS_TO_IGNORE . includes ( key . toLowerCase ( ) ) ;
49
+ } ) . map ( function ( key ) {
50
+ return delete options . headers [ key ] ;
58
51
} ) ;
59
52
60
53
}
@@ -93,22 +86,22 @@ function makePromise(requestInstance, promiseFactoryFn) {
93
86
94
87
function Request ( url , options , f , retryConfig ) {
95
88
// ('url')
96
- if ( _ . isString ( url ) ) {
89
+ if ( _ . isString ( url ) ) {
97
90
// ('url', f)
98
- if ( _ . isFunction ( options ) ) {
91
+ if ( _ . isFunction ( options ) ) {
99
92
f = options ;
100
93
}
101
94
102
- if ( ! _ . isObject ( options ) ) {
95
+ if ( ! _ . isObject ( options ) ) {
103
96
options = { } ;
104
97
}
105
98
106
99
// ('url', {object})
107
100
options . url = url ;
108
101
}
109
102
110
- if ( _ . isObject ( url ) ) {
111
- if ( _ . isFunction ( options ) ) {
103
+ if ( _ . isObject ( url ) ) {
104
+ if ( _ . isFunction ( options ) ) {
112
105
f = options ;
113
106
}
114
107
options = url ;
@@ -123,7 +116,8 @@ function Request(url, options, f, retryConfig) {
123
116
* Option object
124
117
* @type {Object }
125
118
*/
126
- this . options = sanitizeHeaders ( options ) ;
119
+ // this.options = sanitizeHeaders(options);
120
+ this . options = options ;
127
121
128
122
/**
129
123
* Return true if the request should be retried
@@ -135,7 +129,9 @@ function Request(url, options, f, retryConfig) {
135
129
* Return a number representing how long request-retry should wait before trying again the request
136
130
* @type {Boolean } (err, response, body) -> Number
137
131
*/
138
- this . delayStrategy = _ . isFunction ( options . delayStrategy ) ? options . delayStrategy : function ( ) { return this . retryDelay ; } ;
132
+ this . delayStrategy = _ . isFunction ( options . delayStrategy ) ? options . delayStrategy : function ( ) {
133
+ return this . retryDelay ;
134
+ } ;
139
135
140
136
this . _timeout = null ;
141
137
this . _req = null ;
@@ -204,14 +200,14 @@ Request.prototype.abort = function () {
204
200
205
201
// expose request methods from RequestRetry
206
202
[ 'end' , 'on' , 'emit' , 'once' , 'setMaxListeners' , 'start' , 'removeListener' , 'pipe' , 'write' , 'auth' ] . forEach ( function ( requestMethod ) {
207
- Request . prototype [ requestMethod ] = function exposedRequestMethod ( ) {
203
+ Request . prototype [ requestMethod ] = function exposedRequestMethod ( ) {
208
204
return this . _req [ requestMethod ] . apply ( this . _req , arguments ) ;
209
205
} ;
210
206
} ) ;
211
207
212
208
// expose promise methods
213
209
[ 'then' , 'catch' , 'finally' , 'fail' , 'done' ] . forEach ( function ( promiseMethod ) {
214
- Request . prototype [ promiseMethod ] = function exposedPromiseMethod ( ) {
210
+ Request . prototype [ promiseMethod ] = function exposedPromiseMethod ( ) {
215
211
if ( this . _callback ) {
216
212
throw new Error ( 'A callback was provided but waiting a promise, use only one pattern' ) ;
217
213
}
@@ -230,22 +226,22 @@ function Factory(url, options, f) {
230
226
function makeHelper ( obj , verb ) {
231
227
obj [ verb ] = function helper ( url , options , f ) {
232
228
// ('url')
233
- if ( _ . isString ( url ) ) {
229
+ if ( _ . isString ( url ) ) {
234
230
// ('url', f)
235
- if ( _ . isFunction ( options ) ) {
231
+ if ( _ . isFunction ( options ) ) {
236
232
f = options ;
237
233
}
238
234
239
- if ( ! _ . isObject ( options ) ) {
235
+ if ( ! _ . isObject ( options ) ) {
240
236
options = { } ;
241
237
}
242
238
243
239
// ('url', {object})
244
240
options . url = url ;
245
241
}
246
242
247
- if ( _ . isObject ( url ) ) {
248
- if ( _ . isFunction ( options ) ) {
243
+ if ( _ . isObject ( url ) ) {
244
+ if ( _ . isFunction ( options ) ) {
249
245
f = options ;
250
246
}
251
247
options = url ;
@@ -259,13 +255,13 @@ function makeHelper(obj, verb) {
259
255
function defaults ( defaultOptions , defaultF ) {
260
256
var factory = function ( options , f ) {
261
257
if ( typeof options === "string" ) {
262
- options = { uri : options } ;
258
+ options = { uri : options } ;
263
259
}
264
- return Factory . apply ( null , [ extend ( true , { } , defaultOptions , options ) , f || defaultF ] ) ;
260
+ return Factory . apply ( null , [ extend ( true , { } , defaultOptions , options ) , f || defaultF ] ) ;
265
261
} ;
266
262
267
263
factory . defaults = function ( newDefaultOptions , newDefaultF ) {
268
- return defaults . apply ( null , [ extend ( true , { } , defaultOptions , newDefaultOptions ) , newDefaultF || defaultF ] ) ;
264
+ return defaults . apply ( null , [ extend ( true , { } , defaultOptions , newDefaultOptions ) , newDefaultF || defaultF ] ) ;
269
265
} ;
270
266
271
267
factory . Request = Request ;
0 commit comments