Skip to content

Commit

Permalink
fix(stream): try to forward headers
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Oct 20, 2023
1 parent 4615efb commit 415a888
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ export class Stream extends Transform {
return this.#uid
}

pipe<T extends HeaderStream>(destination: T, options?: { end?: boolean }): T {
pipe<T extends HeaderStream>(
destination: T,
options?: { end?: boolean },
headers?: Record<string, any>
): 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',
Expand Down
2 changes: 1 addition & 1 deletion src/transmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class Transmit extends Emittery<TransmitLifecycleHooks> {
*/
$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() })

Expand Down

0 comments on commit 415a888

Please sign in to comment.