fix: 2 downloads made on the same socket caused the second to be logged with wrote size
Massimo Melina committed
Jun 28, 2023 at 23:33 UTC
54cbaaace35d29279d8cfceec0165ceed9192b1c
1 file changed
+2
-1
src/throttler.ts
+2
-1
@@ -43,6 +43,7 @@ export const throttler: Koa.Middleware = async (ctx, next) => {
43
if (!conn) throw 'assert throttler connection'
44
45
const ts = conn[SymThrStr] = new ThrottledStream(ipGroup.group, conn[SymThrStr])
46
+ const offset = ts.getBytesSent()
47
let closed = false
48
49
const DELAY = 1000
@@ -80,7 +81,7 @@ export const throttler: Koa.Middleware = async (ctx, next) => {
81
if (downloadTotal) // preserve this info
82
ctx.response.length = downloadTotal
83
ts.once('end', () => // in case of compressed response, we offer calculation of real size
83
- ctx.state.length = ts.getBytesSent())
84
+ ctx.state.length = ts.getBytesSent() - offset)
85
}
86
87
export function roundSpeed(n: number) {