Skip to content

Commit 27b48bb

Browse files
committed
Fix error & head handling in stream handlers
This ensures that errors result in a client response failure, and that headers are flushed without waiting for the stream to start. This approach is a little basic, and errors don't yet handle this case of browser streams, but I think those are very rarely used and it's unlikely to be relevant.
1 parent d3e505e commit 27b48bb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/rules/requests/request-handlers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,12 @@ export class StreamHandler extends StreamHandlerDefinition {
274274
if (this.headers) dropDefaultHeaders(response);
275275

276276
writeHead(response, this.status, undefined, this.headers);
277+
response.flushHeaders();
278+
277279
this.stream.pipe(response);
278280
this.stream.done = true;
281+
282+
this.stream.on('error', (e) => response.destroy(e));
279283
} else {
280284
throw new Error(stripIndent`
281285
Stream request handler called more than once - this is not supported.

0 commit comments

Comments
 (0)