Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/gateway/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)`)
Expand Down
20 changes: 18 additions & 2 deletions src/mappersmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,23 @@ export const configs = {
withCredentials: false,

/**
* For aditional configurations to the XMLHttpRequest object.
* For additional configurations to the XMLHttpRequest object.
* @param {XMLHttpRequest} xhr
* @default null
*/
configure: null
},

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
Expand All @@ -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: {
Expand Down