@nxtedition/lib 20.3.9 → 20.4.0
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 +66 -0
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import http2 from 'node:http2'
|
|
1
2
|
import createError from 'http-errors'
|
|
2
3
|
import { performance } from 'perf_hooks'
|
|
3
4
|
import requestTarget from 'request-target'
|
|
@@ -222,6 +223,71 @@ export class ServerResponse extends http.ServerResponse {
|
|
|
222
223
|
}
|
|
223
224
|
}
|
|
224
225
|
|
|
226
|
+
export class Http2ServerResponse extends http2.Http2ServerResponse {
|
|
227
|
+
#now = 0
|
|
228
|
+
#created = 0
|
|
229
|
+
#timing = {
|
|
230
|
+
connect: -1,
|
|
231
|
+
headers: -1,
|
|
232
|
+
data: -1,
|
|
233
|
+
complete: -1,
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
get timing() {
|
|
237
|
+
return this.#timing
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
constructor(req) {
|
|
241
|
+
super(req)
|
|
242
|
+
|
|
243
|
+
this.#created = performance.now()
|
|
244
|
+
this.#now = this.#created
|
|
245
|
+
this.#timing.connect = 0
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
flushHeaders() {
|
|
249
|
+
if (this.#timing.headers === -1) {
|
|
250
|
+
this.#timing.headers = performance.now() - this.#now
|
|
251
|
+
this.#now += this.#timing.headers
|
|
252
|
+
}
|
|
253
|
+
return super.flushHeaders()
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
write(chunk, encoding, callback) {
|
|
257
|
+
if (this.#timing.data === -1) {
|
|
258
|
+
this.#timing.data = performance.now() - this.#now
|
|
259
|
+
this.#now += this.#timing.data
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (this.#timing.headers === -1) {
|
|
263
|
+
this.#timing.headers = this.#timing.data
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return super.write(chunk, encoding, callback)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
end(chunk, encoding, callback) {
|
|
270
|
+
if (this.#timing.data === -1) {
|
|
271
|
+
this.#timing.data = performance.now() - this.#now
|
|
272
|
+
this.#now += this.#timing.data
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (this.#timing.headers === -1) {
|
|
276
|
+
this.#timing.headers = this.#timing.data
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return super.end(chunk, encoding, callback)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
destroy(err) {
|
|
283
|
+
if (this.#timing.complete === -1) {
|
|
284
|
+
this.#timing.complete = performance.now() - this.#created
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return super.destroy(err)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
225
291
|
export function createServer(options, ctx, middleware) {
|
|
226
292
|
middleware = Array.isArray(middleware) ? middleware : [middleware]
|
|
227
293
|
middleware = fp.values(middleware)
|