Skip to content

Commit

Permalink
Fixed getUrl for node 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 18, 2020
1 parent 25102d4 commit 560adea
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/web/src.ts/geturl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,28 @@ function getResponse(request: http.ClientRequest): Promise<GetUrlResponse> {
export async function getUrl(href: string, options?: Options): Promise<GetUrlResponse> {
if (options == null) { options = { }; }

// @TODO: Once we drop support for node 8, we can pass the href
// firectly into request and skip adding the components
// to this request object
const url = new URL(href);

const request = {
protocol: url.protocol,
hostname: url.hostname,
port: url.port,
path: (url.pathname + url.search),

method: (options.method || "GET"),
headers: (options.headers || { }),
};

let req: http.ClientRequest = null;
switch (url.protocol) {
case "http:": {
req = http.request(url, request);
case "http:":
req = http.request(request);
break;
}
case "https:":
req = https.request(url, request);
req = https.request(request);
break;
default:
logger.throwError(`unsupported protocol ${ url.protocol }`, Logger.errors.UNSUPPORTED_OPERATION, {
Expand Down

0 comments on commit 560adea

Please sign in to comment.