@@ -218,233 +218,6 @@ function toIsoDateString(d) {
218
218
return d . toISOString ( ) . substring ( 0 , 10 )
219
219
}
220
220
221
- // ( added by 0x000f, 20220910
222
- // bc superagent has hardcoded "indices: false" it prevent to have array indexes in query string
223
- // also added dependencies to project 'cookiejar' and 'qs'
224
- // use in request-manager.js RequestManager._makeRequest()
225
-
226
- /* eslint-disable func-names, yoda, no-new-object, no-param-reassign, no-var, vars-on-top,
227
- global-require, prefer-destructuring, prefer-arrow-callback, no-plusplus, no-return-assign,
228
- no-func-assign, eqeqeq, no-shadow, no-sequences, no-restricted-syntax */
229
- function patchRequest ( Request ) {
230
- const parse = require ( "url" ) . parse
231
- const qs = require ( "qs" )
232
- const https = require ( "https" )
233
- const http = require ( "http" )
234
- const CookieJar = require ( "cookiejar" )
235
-
236
- const exports = {
237
- protocols : {
238
- "http:" : http ,
239
- "https:" : https ,
240
- "http2:" : null // TODO: add http2
241
- }
242
- }
243
-
244
- const hasOwn = Object . hasOwn || function ( object , property ) {
245
- if ( object == null ) {
246
- throw new TypeError ( "Cannot convert undefined or null to object" )
247
- }
248
- return Object . prototype . hasOwnProperty . call ( new Object ( object ) , property )
249
- }
250
-
251
- function _typeof ( obj ) {
252
- "@babel/helpers - typeof"
253
-
254
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol . iterator
255
- ? function ( obj ) {
256
- return typeof obj
257
- }
258
- : function ( obj ) {
259
- return obj && "function" == typeof Symbol && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj
260
- } , _typeof ( obj )
261
- }
262
-
263
- Request . request = function ( ) {
264
- var _this4 = this
265
-
266
- if ( this . req ) return this . req
267
- var options = { }
268
-
269
- try {
270
- var query = qs . stringify ( this . qs , {
271
- // ( changed by 0x000f
272
- // indices: false,
273
- indices : true ,
274
- // changed by 0x000f )
275
- strictNullHandling : true
276
- } )
277
-
278
- if ( query ) {
279
- this . qs = { }
280
-
281
- this . _query . push ( query )
282
- }
283
-
284
- this . _finalizeQueryString ( )
285
- } catch ( err ) {
286
- return this . emit ( "error" , err )
287
- }
288
-
289
- var url = this . url
290
- var retries = this . _retries // Capture backticks as-is from the final query string built above.
291
- // Note: this'll only find backticks entered in req.query(String)
292
- // calls, because qs.stringify unconditionally encodes backticks.
293
-
294
- var queryStringBackticks
295
-
296
- if ( url . includes ( "`" ) ) {
297
- var queryStartIndex = url . indexOf ( "?" )
298
-
299
- if ( queryStartIndex !== - 1 ) {
300
- var queryString = url . slice ( queryStartIndex + 1 )
301
- queryStringBackticks = queryString . match ( / ` | % 6 0 / g)
302
- }
303
- } // default to http://
304
-
305
- if ( url . indexOf ( "http" ) !== 0 ) url = "http://" . concat ( url )
306
- url = parse ( url ) // See https://github.com/visionmedia/superagent/issues/1367
307
-
308
- if ( queryStringBackticks ) {
309
- var i = 0
310
- url . query = url . query . replace ( / % 6 0 / g, function ( ) {
311
- return queryStringBackticks [ i ++ ]
312
- } )
313
- url . search = "?" . concat ( url . query )
314
- url . path = url . pathname + url . search
315
- } // support unix sockets
316
-
317
- if ( / ^ h t t p s ? \+ u n i x : / . test ( url . protocol ) === true ) {
318
- // get the protocol
319
- url . protocol = "" . concat ( url . protocol . split ( "+" ) [ 0 ] , ":" ) // get the socket, path
320
-
321
- var unixParts = url . path . match ( / ^ ( [ ^ / ] + ) ( .+ ) $ / )
322
- options . socketPath = unixParts [ 1 ] . replace ( / % 2 F / g, "/" )
323
- url . path = unixParts [ 2 ]
324
- } // Override IP address of a hostname
325
-
326
- if ( this . _connectOverride ) {
327
- var _url = url
328
- var hostname = _url . hostname
329
- var match = hostname in this . _connectOverride ? this . _connectOverride [ hostname ] : this . _connectOverride [ "*" ]
330
-
331
- if ( match ) {
332
- // backup the real host
333
- if ( ! this . _header . host ) {
334
- this . set ( "host" , url . host )
335
- }
336
-
337
- var newHost
338
- var newPort
339
-
340
- if ( _typeof ( match ) === "object" ) {
341
- newHost = match . host
342
- newPort = match . port
343
- } else {
344
- newHost = match
345
- newPort = url . port
346
- } // wrap [ipv6]
347
-
348
- url . host = / : / . test ( newHost ) ? "[" . concat ( newHost , "]" ) : newHost
349
-
350
- if ( newPort ) {
351
- url . host += ":" . concat ( newPort )
352
- url . port = newPort
353
- }
354
-
355
- url . hostname = newHost
356
- }
357
- } // options
358
-
359
- options . method = this . method
360
- options . port = url . port
361
- options . path = url . path
362
- options . host = url . hostname
363
- options . ca = this . _ca
364
- options . key = this . _key
365
- options . pfx = this . _pfx
366
- options . cert = this . _cert
367
- options . passphrase = this . _passphrase
368
- options . agent = this . _agent
369
- options . lookup = this . _lookup
370
- options . rejectUnauthorized = typeof this . _disableTLSCerts === "boolean" ? ! this . _disableTLSCerts : process . env . NODE_TLS_REJECT_UNAUTHORIZED !== "0" // Allows request.get('https://1.2.3.4/').set('Host', 'example.com')
371
-
372
- if ( this . _header . host ) {
373
- options . servername = this . _header . host . replace ( / : \d + $ / , "" )
374
- }
375
-
376
- if ( this . _trustLocalhost && / ^ (?: l o c a l h o s t | 1 2 7 \. 0 \. 0 \. \d + | ( 0 * : ) + : 0 * 1 ) $ / . test ( url . hostname ) ) {
377
- options . rejectUnauthorized = false
378
- } // initiate request
379
-
380
- var module_ = this . _enableHttp2 ? exports . protocols [ "http2:" ] . setProtocol ( url . protocol ) : exports . protocols [ url . protocol ] // request
381
-
382
- this . req = module_ . request ( options )
383
- var req = this . req // set tcp no delay
384
-
385
- req . setNoDelay ( true )
386
-
387
- if ( options . method !== "HEAD" ) {
388
- req . setHeader ( "Accept-Encoding" , "gzip, deflate" )
389
- }
390
-
391
- this . protocol = url . protocol
392
- this . host = url . host // expose events
393
-
394
- req . once ( "drain" , function ( ) {
395
- _this4 . emit ( "drain" )
396
- } )
397
- req . on ( "error" , function ( error ) {
398
- // flag abortion here for out timeouts
399
- // because node will emit a faux-error "socket hang up"
400
- // when request is aborted before a connection is made
401
- // if not the same, we are in the **old** (cancelled) request,
402
- // so need to continue (same as for above)
403
- if ( _this4 . _aborted ) return
404
-
405
- // if we've received a response then we don't want to let
406
- // an error in the request blow up the response
407
- if ( _this4 . _retries !== retries ) return
408
-
409
- if ( _this4 . response ) return
410
-
411
- _this4 . callback ( error )
412
- } ) // auth
413
-
414
- if ( url . auth ) {
415
- var auth = url . auth . split ( ":" )
416
- this . auth ( auth [ 0 ] , auth [ 1 ] )
417
- }
418
-
419
- if ( this . username && this . password ) {
420
- this . auth ( this . username , this . password )
421
- }
422
-
423
- for ( var key in this . header ) {
424
- if ( hasOwn ( this . header , key ) ) req . setHeader ( key , this . header [ key ] )
425
- } // add cookies
426
-
427
- if ( this . cookies ) {
428
- if ( hasOwn ( this . _header , "cookie" ) ) {
429
- // merge
430
- var temporaryJar = new CookieJar . CookieJar ( )
431
- temporaryJar . setCookies ( this . _header . cookie . split ( "" ) )
432
- temporaryJar . setCookies ( this . cookies . split ( "" ) )
433
- req . setHeader ( "Cookie" , temporaryJar . getCookies ( CookieJar . CookieAccessInfo . All ) . toValueString ( ) )
434
- } else {
435
- req . setHeader ( "Cookie" , this . cookies )
436
- }
437
- }
438
- return req
439
- }
440
- }
441
- /* eslint-disable func-names, yoda, no-new-object, no-param-reassign, no-var, vars-on-top,
442
- global-require, prefer-destructuring, prefer-arrow-callback, no-plusplus, no-return-assign,
443
- no-func-assign, eqeqeq, no-shadow, no-sequences, no-restricted-syntax */
444
-
445
- exports . patchRequest = patchRequest
446
- // added by 0x000f, 20220910 )
447
-
448
221
exports . ILogger = ILogger
449
222
exports . CustomInternalPostProcessing = CustomInternalPostProcessing
450
223
0 commit comments