Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ var Writable = require("stream").Writable; | |
var assert = require("assert"); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
var debug = require("./debug"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
// Whether to use the native URL object or the legacy url module | ||
var hasNativeURL = typeof URL !== "undefined"; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
// Create handlers that pass events from native requests | ||
var events = ["abort", "aborted", "connect", "error", "socket", "timeout"]; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
var eventHandlers = Object.create(null); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
@@ -15,12 +18,12 @@ events.forEach(function (event) { | |
}; | ||
}); | ||
|
||
// Error types with codes | ||
var InvalidUrlError = createErrorType( | ||
This comment has been minimized.
Sorry, something went wrong. |
||
"ERR_INVALID_URL", | ||
"Invalid URL", | ||
TypeError | ||
); | ||
// Error types with codes | ||
var RedirectionError = createErrorType( | ||
This comment has been minimized.
Sorry, something went wrong. |
||
"ERR_FR_REDIRECTION_FAILURE", | ||
"Redirected request failed" | ||
|
@@ -426,7 +429,7 @@ RedirectableRequest.prototype._processResponse = function (response) { | |
url.format(Object.assign(currentUrlParts, { host: currentHost })); | ||
|
||
// Determine the URL of the redirection | ||
var redirectUrl = url.resolve(currentUrl, location); | ||
var redirectUrl = resolveUrl(location, currentUrl); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
// Create the redirected request | ||
debug("redirecting to", redirectUrl); | ||
|
@@ -494,7 +497,7 @@ function wrap(protocols) { | |
} | ||
input = parsed; | ||
} | ||
else if (URL && (input instanceof URL)) { | ||
else if (hasNativeURL && (input instanceof URL)) { | ||
input = urlToOptions(input); | ||
} | ||
else { | ||
|
@@ -538,9 +541,15 @@ function wrap(protocols) { | |
return exports; | ||
} | ||
|
||
/* istanbul ignore next */ | ||
function noop() { /* empty */ } | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rhuankarlus
|
||
|
||
function resolveUrl(relative, base) { | ||
return !hasNativeURL ? | ||
/* istanbul ignore next */ | ||
url.resolve(base, relative) : | ||
(new URL(relative, base)).href; | ||
} | ||
|
||
// from https://github.com/nodejs/node/blob/master/lib/internal/url.js | ||
function urlToOptions(urlObject) { | ||
var options = { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
you could use const instead of var