massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-go / node_modules / node-fetch / lib / index.mjs
index ecf59af8c773648a38e95db9f54d12fd5f3dd9ec..31260e504864660ca99de46d6838f4c1f1a9e18b 100644 (file)
@@ -1,6 +1,7 @@
 import Stream from 'stream';
 import http from 'http';
 import Url from 'url';
+import whatwgUrl from 'whatwg-url';
 import https from 'https';
 import zlib from 'zlib';
 
@@ -1135,11 +1136,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;
 
 /**
@@ -1176,14 +1198,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';