-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer native URL instead of legacy url.resolve.
- Loading branch information
1 parent
72bc2a4
commit 1cba8e8
Showing
2 changed files
with
14 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
you could use const instead of var