undici-thread-interceptor
Advanced tools
Comparing version 0.10.2 to 0.10.3
@@ -134,2 +134,4 @@ 'use strict' | ||
handler.onResponseEnd(controller, []) | ||
hooks.fireOnClientResponseEnd(newOpts, res, clientCtx) | ||
})) | ||
@@ -136,0 +138,0 @@ |
@@ -9,2 +9,3 @@ 'use strict' | ||
'onClientResponse', | ||
'onClientResponseEnd', | ||
'onClientError' | ||
@@ -21,2 +22,3 @@ ] | ||
onClientResponse = noop | ||
onClientResponseEnd = noop | ||
onClientError = noop | ||
@@ -60,2 +62,6 @@ | ||
fireOnClientResponseEnd (req, res, ctx) { | ||
return this.onClientResponseEnd(req, res, ctx) | ||
} | ||
fireOnClientError (req, res, ctx, error) { | ||
@@ -62,0 +68,0 @@ return this.onClientError(req, res, ctx, error) |
{ | ||
"name": "undici-thread-interceptor", | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"description": "An Undici interceptor that routes requests over a worker thread", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -163,2 +163,3 @@ # undici-thread-interceptor | ||
- `onClientResponse(req, res, clientCtx)` | ||
- `onClientResponseEnd(req, res, clientCtx)` | ||
- `onClientError(req, res, clientCtx, error)` | ||
@@ -165,0 +166,0 @@ |
@@ -22,4 +22,4 @@ 'use strict' | ||
const { dataInRequest } = req | ||
console.log('onServerReponse called:', dataInRequest) | ||
console.log('onServerResponse called:', dataInRequest) | ||
} | ||
}) |
@@ -109,2 +109,24 @@ 'use strict' | ||
test('hooks - onClientResponseEnd', async (t) => { | ||
const worker = new Worker(join(__dirname, 'fixtures', 'worker1.js')) | ||
t.after(() => worker.terminate()) | ||
let hookCalled = null | ||
const interceptor = createThreadInterceptor({ | ||
domain: '.local', | ||
onClientResponseEnd: (_req, res) => { | ||
hookCalled = Buffer.from(res.rawPayload).toString() | ||
} | ||
}) | ||
interceptor.route('myserver', worker) | ||
const agent = new Agent().compose(interceptor) | ||
const { statusCode } = await request('http://myserver.local', { | ||
dispatcher: agent, | ||
}) | ||
strictEqual(statusCode, 200) | ||
deepStrictEqual(hookCalled, '{"hello":"world"}') | ||
}) | ||
test('hooks - onClientError', async (t) => { | ||
@@ -230,3 +252,3 @@ const worker = new Worker(join(__dirname, 'fixtures', 'error.js')) | ||
await sleep(300) | ||
deepStrictEqual(lines, ['onServerRequest called {"method":"GET","url":"/","headers":{"host":"myserver.local"}}', 'onServerReponse called: propagated']) | ||
deepStrictEqual(lines, ['onServerRequest called {"method":"GET","url":"/","headers":{"host":"myserver.local"}}', 'onServerResponse called: propagated']) | ||
}) | ||
@@ -233,0 +255,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74399
1997
215