Skip to content

Commit

Permalink
fix some version of Node with single slash protocol in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris committed Dec 29, 2018
1 parent 4814647 commit 049bb95
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/cors-anywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ function onProxyResponse(proxy, proxyReq, proxyRes, req, res) {
* @return {object} URL parsed using url.parse
*/
function parseURL(req_url) {

//fix some version of Node with incorrected encoded url as http:/something or https:/something
if (req_url.startsWith('http:/') && !req_url.startsWith('http://')){
req_url = 'http://' + req_url.slice(6);
} else if (req_url.startsWith('https:/') && !req_url.startsWith('https://')){
req_url = 'https://' + req_url.slice(7);
}
var match = req_url.match(/^(?:(https?:)?\/\/)?(([^\/?]+?)(?::(\d{0,5})(?=[\/?]|$))?)([\/?][\S\s]*|$)/i);
// ^^^^^^^ ^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^
// 1:protocol 3:hostname 4:port 5:path + query string
Expand Down

0 comments on commit 049bb95

Please sign in to comment.