undici-thread-interceptor
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -443,3 +443,3 @@ 'use strict' | ||
/* c8 ignore next 7 */ | ||
if (data[0] instanceof Buffer || data[0] instanceof Uint8Array) { | ||
if (data[0] instanceof Buffer || data[0] instanceof Uint8Array || data.length === 0) { | ||
return Buffer.concat(data) | ||
@@ -446,0 +446,0 @@ } else { |
{ | ||
"name": "undici-thread-interceptor", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "An Undici interceptor that routes requests over a worker thread", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -499,1 +499,20 @@ 'use strict' | ||
}) | ||
test('empty-stream', async (t) => { | ||
const worker = new Worker(join(__dirname, 'fixtures', 'worker1.js')) | ||
t.after(() => worker.terminate()) | ||
const interceptor = createThreadInterceptor({ | ||
domain: '.local', | ||
}) | ||
interceptor.route('myserver', worker) | ||
const agent = new Agent().compose(interceptor) | ||
const { statusCode, body } = await request('http://myserver.local/empty-stream', { | ||
dispatcher: agent, | ||
}) | ||
strictEqual(statusCode, 200) | ||
deepStrictEqual(await body.text(), '') | ||
}) |
@@ -94,2 +94,13 @@ 'use strict' | ||
app.get('/empty-stream', (req, reply) => { | ||
// The content-lengh header is necessary to make sure that | ||
// the mesh network collects the whole body | ||
reply.header('content-length', 0) | ||
reply.send(new Readable({ | ||
read () { | ||
this.push(null) | ||
}, | ||
})) | ||
}) | ||
app.post('/echo-body', (req, reply) => { | ||
@@ -96,0 +107,0 @@ reply.send(req.body) |
90465
2517