massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-go / node_modules / node-fetch / lib / index.js
index 4b241bfbf8bee961f077bf9574150660355928cd..45d3985c37d5b1814742a7c7b81f8aa6cb27f7f2 100644 (file)
@@ -7,6 +7,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
 var Stream = _interopDefault(require('stream'));
 var http = _interopDefault(require('http'));
 var Url = _interopDefault(require('url'));
+var whatwgUrl = _interopDefault(require('whatwg-url'));
 var https = _interopDefault(require('https'));
 var zlib = _interopDefault(require('zlib'));
 
@@ -1141,11 +1142,32 @@ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
 });
 
 const INTERNALS$2 = Symbol('Request internals');
+const URL = Url.URL || whatwgUrl.URL;
 
 // fix an issue where "format", "parse" aren't a named export for node <10
 const parse_url = Url.parse;
 const format_url = Url.format;
 
+/**
+ * Wrapper around `new URL` to handle arbitrary URLs
+ *
+ * @param  {string} urlStr
+ * @return {void}
+ */
+function parseURL(urlStr) {
+       /*
+       Check whether the URL is absolute or not
+               Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
+       Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
+ */
+       if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) {
+               urlStr = new URL(urlStr).toString();
+       }
+
+       // Fallback to old implementation for arbitrary URLs
+       return parse_url(urlStr);
+}
+
 const streamDestructionSupported = 'destroy' in Stream.Readable.prototype;
 
 /**
@@ -1182,14 +1204,14 @@ class Request {
                                // in order to support Node.js' Url objects; though WHATWG's URL objects
                                // will fall into this branch also (since their `toString()` will return
                                // `href` property anyway)
-                               parsedURL = parse_url(input.href);
+                               parsedURL = parseURL(input.href);
                        } else {
                                // coerce input to a string before attempting to parse
-                               parsedURL = parse_url(`${input}`);
+                               parsedURL = parseURL(`${input}`);
                        }
                        input = {};
                } else {
-                       parsedURL = parse_url(input.url);
+                       parsedURL = parseURL(input.url);
                }
 
                let method = init.method || input.method || 'GET';