@nxtedition/lib 15.0.42 → 15.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/http.js +31 -13
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -7,7 +7,6 @@ const compose = require('koa-compose')
|
|
|
7
7
|
const http = require('http')
|
|
8
8
|
const fp = require('lodash/fp')
|
|
9
9
|
const tp = require('timers/promises')
|
|
10
|
-
const { AbortError } = require('./errors')
|
|
11
10
|
|
|
12
11
|
const ERR_HEADER_EXPR =
|
|
13
12
|
/^(content-length|content-type|te|host|upgrade|trailers|connection|keep-alive|http2-settings|transfer-encoding|proxy-connection|proxy-authenticate|proxy-authorization)$/i
|
|
@@ -60,19 +59,34 @@ module.exports.request = async function request(ctx, next) {
|
|
|
60
59
|
reqLogger.trace({ req }, 'request started')
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
await Promise.all([
|
|
63
|
+
next(),
|
|
64
|
+
new Promise((resolve, reject) => {
|
|
65
|
+
res
|
|
66
|
+
.on('timeout', function () {
|
|
67
|
+
this.destroy(new createError.RequestTimeout())
|
|
68
|
+
})
|
|
69
|
+
.on('error', (err) => {
|
|
70
|
+
reqLogger.error({ err }, 'response error')
|
|
71
|
+
reject(err)
|
|
72
|
+
})
|
|
73
|
+
.on('close', () => {
|
|
74
|
+
reqLogger.debug('response closed')
|
|
75
|
+
resolve(null)
|
|
76
|
+
})
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
req
|
|
79
|
+
.on('timeout', function () {
|
|
80
|
+
this.destroy(new createError.RequestTimeout())
|
|
81
|
+
})
|
|
82
|
+
.on('error', (err) => {
|
|
83
|
+
reqLogger.error({ err }, 'request error')
|
|
84
|
+
})
|
|
85
|
+
.on('close', () => {
|
|
86
|
+
reqLogger.debug('request closed')
|
|
87
|
+
})
|
|
88
|
+
}),
|
|
89
|
+
])
|
|
76
90
|
|
|
77
91
|
assert(res.writableEnded)
|
|
78
92
|
assert(res.statusCode)
|
|
@@ -90,6 +104,8 @@ module.exports.request = async function request(ctx, next) {
|
|
|
90
104
|
} else {
|
|
91
105
|
reqLogger.trace('request completed')
|
|
92
106
|
}
|
|
107
|
+
|
|
108
|
+
ac.abort()
|
|
93
109
|
} catch (err) {
|
|
94
110
|
const reason = ac.signal.reason
|
|
95
111
|
const responseTime = Math.round(performance.now() - startTime)
|
|
@@ -161,6 +177,8 @@ module.exports.request = async function request(ctx, next) {
|
|
|
161
177
|
res.destroy()
|
|
162
178
|
}
|
|
163
179
|
}
|
|
180
|
+
|
|
181
|
+
ac.abort(err)
|
|
164
182
|
}
|
|
165
183
|
}
|
|
166
184
|
|