| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 37369eb commit 2bf9a4a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -255,25 +255,33 @@ Agent.prototype._evictSession = function _evictSession(key) { | |||
| 255 | 255 | ||
| 256 | 256 | const globalAgent = new Agent(); | |
| 257 | 257 | ||
| 258 | - function request(options, cb) { | ||
| 259 | - if (typeof options === 'string') { | ||
| 260 | - options = url.parse(options); | ||
| 258 | + function request(...args) { | ||
| 259 | + let options = {}; | ||
| 260 | + | ||
| 261 | + if (typeof args[0] === 'string') { | ||
| 262 | + const urlStr = args.shift(); | ||
| 263 | + options = url.parse(urlStr); | ||
| 261 | 264 | if (!options.hostname) { | |
| 262 | 265 | throw new ERR_INVALID_DOMAIN_NAME(); | |
| 263 | 266 | } | |
| 264 | - } else if (options && options[searchParamsSymbol] && | ||
| 265 | - options[searchParamsSymbol][searchParamsSymbol]) { | ||
| 267 | + } else if (args[0] && args[0][searchParamsSymbol] && | ||
| 268 | + args[0][searchParamsSymbol][searchParamsSymbol]) { | ||
| 266 | 269 | // url.URL instance | |
| 267 | - options = urlToOptions(options); | ||
| 268 | - } else { | ||
| 269 | - options = util._extend({}, options); | ||
| 270 | + options = urlToOptions(args.shift()); | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + if (args[0] && typeof args[0] !== 'function') { | ||
| 274 | + options = util._extend(options, args.shift()); | ||
| 270 | 275 | } | |
| 276 | + | ||
| 271 | 277 | options._defaultAgent = globalAgent; | |
| 272 | - return new ClientRequest(options, cb); | ||
| 278 | + args.unshift(options); | ||
| 279 | + | ||
| 280 | + return new ClientRequest(...args); | ||
| 273 | 281 | } | |
| 274 | 282 | ||
| 275 | - function get(options, cb) { | ||
| 276 | - const req = request(options, cb); | ||
| 283 | + function get(input, options, cb) { | ||
| 284 | + const req = request(input, options, cb); | ||
| 277 | 285 | req.end(); | |
| 278 | 286 | return req; | |
| 279 | 287 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,46 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const https = require('https'); | ||
| 5 | + const fixtures = require('../common/fixtures'); | ||
| 6 | + | ||
| 7 | + if (!common.hasCrypto) | ||
| 8 | + common.skip('missing crypto'); | ||
| 9 | + | ||
| 10 | + const options = { | ||
| 11 | + key: fixtures.readKey('agent1-key.pem'), | ||
| 12 | + cert: fixtures.readKey('agent1-cert.pem'), | ||
| 13 | + ca: fixtures.readKey('ca1-cert.pem') | ||
| 14 | + }; | ||
| 15 | + | ||
| 16 | + // Test providing both a url and options, with the options partially | ||
| 17 | + // replacing address and port portions of the URL provided. | ||
| 18 | + { | ||
| 19 | + const server = https.createServer( | ||
| 20 | + options, | ||
| 21 | + common.mustCall((req, res) => { | ||
| 22 | + assert.strictEqual(req.url, '/testpath'); | ||
| 23 | + res.end(); | ||
| 24 | + server.close(); | ||
| 25 | + }) | ||
| 26 | + ); | ||
| 27 | + | ||
| 28 | + server.listen( | ||
| 29 | + 0, | ||
| 30 | + common.mustCall(() => { | ||
| 31 | + https.get( | ||
| 32 | + 'https://example.com/testpath', | ||
| 33 | + | ||
| 34 | + { | ||
| 35 | + hostname: 'localhost', | ||
| 36 | + port: server.address().port, | ||
| 37 | + rejectUnauthorized: false | ||
| 38 | + }, | ||
| 39 | + | ||
| 40 | + common.mustCall((res) => { | ||
| 41 | + res.resume(); | ||
| 42 | + }) | ||
| 43 | + ); | ||
| 44 | + }) | ||
| 45 | + ); | ||
| 46 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments