Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a single param to request (issue #1620) #1693

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -91,7 +91,7 @@ export default async function fetch(url, options_) {
};

// Send request
const request_ = send(parsedURL.toString(), options);
const request_ = send(options);

if (signal) {
signal.addEventListener('abort', abortAndFinalize);
Expand Down
17 changes: 15 additions & 2 deletions src/request.js
Expand Up @@ -297,18 +297,31 @@ export const getNodeRequestOptions = request => {

const search = getSearch(parsedURL);

// Pass the full URL directly to request(), but overwrite the following
// options:
// Provide full options from URL (issue #1620)
const options = {
protocol: parsedURL.protocol,
hostname: parsedURL.hostname.startsWith("[") && parsedURL.hostname.endsWith("]") ? parsedURL.hostname.slice(1, -1) : parsedURL.hostname,
pathname: parsedURL.pathname,
// Overwrite search to retain trailing ? (issue #776)
path: parsedURL.pathname + search,
search: parsedURL.search,
hash: parsedURL.hash,
href: parsedURL.href,
// The following options are not expressed in the URL
method: request.method,
headers: headers[Symbol.for('nodejs.util.inspect.custom')](),
insecureHTTPParser: request.insecureHTTPParser,
agent
};

if (parsedURL.username || parsedURL.password) {
options.auth = `${decodeURIComponent(parsedURL.username)}:${decodeURIComponent(parsedURL.password)}`;
}

if (parsedURL.port !== '') {
options.port = Number(parsedURL.port);
}

return {
/** @type {URL} */
parsedURL,
Expand Down