Skip to content

Commit

Permalink
fix(http.request): Cast URL to string before sending it to NodeJS core (
Browse files Browse the repository at this point in the history
#1378)

* Add some jsdoc

* cast url to string before sending it to NodeJS core
  • Loading branch information
jimmywarting committed Nov 12, 2021
1 parent 3f0e0c2 commit 0284826
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -78,7 +78,7 @@ export default async function fetch(url, options_) {
};

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

if (signal) {
signal.addEventListener('abort', abortAndFinalize);
Expand Down
12 changes: 8 additions & 4 deletions src/request.js
@@ -1,4 +1,3 @@

/**
* Request.js
*
Expand All @@ -21,7 +20,7 @@ const INTERNALS = Symbol('Request internals');
/**
* Check if `obj` is an instance of Request.
*
* @param {*} obj
* @param {*} object
* @return {boolean}
*/
const isRequest = object => {
Expand Down Expand Up @@ -133,14 +132,17 @@ export default class Request extends Body {
this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || '';
}

/** @returns {string} */
get method() {
return this[INTERNALS].method;
}

/** @returns {string} */
get url() {
return formatUrl(this[INTERNALS].parsedURL);
}

/** @returns {Headers} */
get headers() {
return this[INTERNALS].headers;
}
Expand All @@ -149,6 +151,7 @@ export default class Request extends Body {
return this[INTERNALS].redirect;
}

/** @returns {AbortSignal} */
get signal() {
return this[INTERNALS].signal;
}
Expand Down Expand Up @@ -206,8 +209,8 @@ Object.defineProperties(Request.prototype, {
/**
* Convert a Request to Node.js http request options.
*
* @param Request A Request instance
* @return Object The options object to be passed to http.request
* @param {Request} request - A Request instance
* @return The options object to be passed to http.request
*/
export const getNodeRequestOptions = request => {
const {parsedURL} = request[INTERNALS];
Expand Down Expand Up @@ -296,6 +299,7 @@ export const getNodeRequestOptions = request => {
};

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

0 comments on commit 0284826

Please sign in to comment.