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

Commit

Permalink
Replace url.parse with the URL constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 8, 2019
1 parent 9de2dd3 commit 78ac59a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/fetchResource.js
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
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
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
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

0 comments on commit 78ac59a

Please sign in to comment.