Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Replace url.parse with the URL constructor. #253

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/fetchResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';

const url = require('url');
const { URL } = require('url');
const zlib = require('zlib');
const moduleForProtocol = require('./moduleForProtocol');
const processResource = require('./processResource');
Expand All @@ -24,10 +24,10 @@ const fetchResource = (resourceUrl, cb) => {
return cb(false);
}

const urlObject = url.parse(resourceUrl);
const urlObject = new URL(resourceUrl);
const options = {
hostname: urlObject.hostname,
path: urlObject.path,
path: urlObject.pathname,
headers: {
Origin: 'https://www.srihash.org/'
}
Expand Down
4 changes: 2 additions & 2 deletions lib/guessResourceType.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

const path = require('path');
const url = require('url');
const { URL } = require('url');
const resourceTypes = require('./data/resourceTypes');

/**
Expand All @@ -28,7 +28,7 @@ const guessResourceType = (resource) => {
}

// Match against file extensions
const ext = path.extname(url.parse(resource.url).pathname)
const ext = path.extname(new URL(resource.url).pathname)
.replace('.', '')
.toLowerCase();

Expand Down
4 changes: 2 additions & 2 deletions lib/moduleForProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const http = require('http');
const https = require('https');
const url = require('url');
const { URL } = require('url');

/**
* Choose corresponding module (http or https) for downloading a resource.
Expand All @@ -15,7 +15,7 @@ const url = require('url');
* @return {Object} http or https module
*/
const moduleForProtocol = (urlString) => {
const urlObject = url.parse(urlString);
const urlObject = new URL(urlString);

if (!urlObject.protocol) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/upgradeToHttps.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const secureHosts = require('./data/secureHosts');
*/
const upgradeToHttps = (urlString) => {
// Prepend http for protocol-less URL's
const urlObject = url.parse(urlString);
const urlObject = new url.URL(urlString);

// Upgrade http protocol to https, if host is on the secureHosts list
if (urlObject.protocol === 'http:' && secureHosts.includes(urlObject.hostname)) {
Expand Down