Browse Source

`url` arg optimizations (#329)

helper-loop
Steven Vachon 8 years ago
committed by Sindre Sorhus
parent
commit
3f117379e6
  1. 19
      index.js
  2. 3
      package.json

19
index.js

@ -10,6 +10,7 @@ const isStream = require('is-stream');
const getStream = require('get-stream');
const timedOut = require('timed-out');
const urlParseLax = require('url-parse-lax');
const urlToOptions = require('url-to-options');
const lowercaseKeys = require('lowercase-keys');
const decompressResponse = require('decompress-response');
const isRetryAllowed = require('is-retry-allowed');
@ -262,23 +263,15 @@ function asStream(opts) {
function normalizeArguments(url, opts) {
if (typeof url !== 'string' && typeof url !== 'object') {
throw new TypeError(`Parameter \`url\` must be a string or object, not ${typeof url}`);
}
if (typeof url === 'string') {
} else if (typeof url === 'string') {
url = url.replace(/^unix:/, 'http://$&');
url = urlParseLax(url);
if (url.auth) {
throw new Error('Basic authentication must be done with auth option');
}
} else if (isURL.lenient(url)) {
url = urlToOptions(url);
}
if (isURL.lenient(url)) {
url = urlParseLax(url.href);
if (url.auth) {
throw new Error('Basic authentication must be done with auth option');
}
if (url.auth) {
throw new Error('Basic authentication must be done with auth option');
}
opts = Object.assign(

3
package.json

@ -62,7 +62,8 @@
"p-timeout": "^1.1.1",
"safe-buffer": "^5.0.1",
"timed-out": "^4.0.0",
"url-parse-lax": "^1.0.0"
"url-parse-lax": "^1.0.0",
"url-to-options": "^1.0.1"
},
"devDependencies": {
"ava": "^0.19.1",

Loading…
Cancel
Save