From 415a8889bb8eb713a9086e6e2813926723fc054f Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Fri, 20 Oct 2023 19:14:29 +0200 Subject: [PATCH] fix(stream): try to forward headers --- src/stream.ts | 7 ++++++- src/transmit.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/stream.ts b/src/stream.ts index d5e17a0..8752114 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -52,10 +52,15 @@ export class Stream extends Transform { return this.#uid } - pipe(destination: T, options?: { end?: boolean }): T { + pipe( + destination: T, + options?: { end?: boolean }, + headers?: Record + ): T { if (destination.writeHead) { // @see https://github.com/dunglas/mercure/blob/9e080c8dc9a141d4294412d14efdecfb15bf7f43/subscribe.go#L219 destination.writeHead(200, { + ...headers, 'Cache-Control': 'private, no-cache, no-store, must-revalidate, max-age=0, no-transform', 'Connection': 'keep-alive', 'Content-Type': 'text/event-stream', diff --git a/src/transmit.ts b/src/transmit.ts index 8aa1c5c..3897cc4 100644 --- a/src/transmit.ts +++ b/src/transmit.ts @@ -71,7 +71,7 @@ export class Transmit extends Emittery { */ $createStream(request: Request, response: Response): void { const stream = new Stream(request.input('uid'), request.request) - stream.pipe(response.response) + stream.pipe(response.response, undefined, response.getHeaders()) void this.emit('connect', { uid: stream.getUid() })