diff --git a/src/gateway/http.js b/src/gateway/http.js index 33a58840..254443ce 100644 --- a/src/gateway/http.js +++ b/src/gateway/http.js @@ -66,6 +66,10 @@ HTTP.prototype = Gateway.extends({ const httpOptions = this.options().HTTP + if (httpOptions.useSocketConnectionTimeout) { + requestParams['timeout'] = timeout + } + if (httpOptions.configure) { assign(requestParams, httpOptions.configure(requestParams)) } @@ -103,7 +107,11 @@ HTTP.prototype = Gateway.extends({ body && httpRequest.write(body) if (timeout) { - httpRequest.setTimeout(timeout, () => { + if (!httpOptions.useSocketConnectionTimeout) { + httpRequest.setTimeout(timeout) + } + + httpRequest.on('timeout', () => { this.canceled = true httpRequest.abort() const error = createTimeoutError(`Timeout (${timeout}ms)`) diff --git a/src/mappersmith.js b/src/mappersmith.js index 290cac06..9e27ad2d 100644 --- a/src/mappersmith.js +++ b/src/mappersmith.js @@ -54,7 +54,7 @@ export const configs = { withCredentials: false, /** - * For aditional configurations to the XMLHttpRequest object. + * For additional configurations to the XMLHttpRequest object. * @param {XMLHttpRequest} xhr * @default null */ @@ -62,6 +62,15 @@ export const configs = { }, HTTP: { + /** + * Enable this option to evaluate timeout on entire request durations, + * including DNS resolution and socket connection. + * + * See original nodejs issue: https://github.com/nodejs/node/pull/8101 + * + * @default false + */ + useSocketConnectionTimeout: false, /** * For additional configurations to the http/https module * For http: https://nodejs.org/api/http.html#http_http_request_options_callback @@ -70,7 +79,14 @@ export const configs = { * @param {object} options * @default null */ - configure: null + configure: null, + onRequestWillStart: null, + onRequestSocketAssigned: null, + onSocketLookup: null, + onSocketConnect: null, + onSocketSecureConnect: null, + onResponseReadable: null, + onResponseEnd: null }, Fetch: {