diff --git a/lib/net/FetchHttpClient.js b/lib/net/FetchHttpClient.js index 8ced9a42af..de27879183 100644 --- a/lib/net/FetchHttpClient.js +++ b/lib/net/FetchHttpClient.js @@ -3,9 +3,12 @@ const {HttpClient, HttpClientResponse} = require('./HttpClient'); /** - * HTTP client which uses a `fetch` function to issue requests. This fetch - * function is expected to be the Web Fetch API function or an equivalent, such - * as the function provided by the node-fetch package (https://github.com/node-fetch/node-fetch). + * HTTP client which uses a `fetch` function to issue requests. + * + * By default relies on the global `fetch` function, but an optional function + * can be passed in. If passing in a function, it is expected to match the Web + * Fetch API. As an example, this could be the function provided by the + * node-fetch package (https://github.com/node-fetch/node-fetch). */ class FetchHttpClient extends HttpClient { constructor(fetchFn) { @@ -36,7 +39,8 @@ class FetchHttpClient extends HttpClient { ); url.port = port; - const fetchPromise = this._fetchFn(url.toString(), { + const fetchFn = this._fetchFn || fetch; + const fetchPromise = fetchFn(url.toString(), { method, headers, body: requestData || undefined,