Skip to content

Commit 52d12f4

Browse files
committed
fix: fix sse connection logging
1 parent eb16c22 commit 52d12f4

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/browser/sse.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,23 @@ class ServerSentEventHandler<
100100

101101
return super.predicate(args)
102102
}
103+
104+
async log(args: { request: Request; response: Response }): Promise<void> {
105+
super.log({
106+
request: args.request,
107+
108+
/**
109+
* @note Construct a placeholder response since SSE response
110+
* is being streamed and cannot be cloned/consumed at this point.
111+
* This also allows us to rely on the same logging logic as in HTTP handlers.
112+
*/
113+
response: new Response('[streaming]', {
114+
status: args.response.status,
115+
statusText: args.response.statusText,
116+
headers: args.response.headers,
117+
}),
118+
})
119+
}
103120
}
104121

105122
type Values<T> = T[keyof T]

test/browser/sse-api/sse.server.connect.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ test('makes the actual request when called "server.connect()"', async ({
4141

4242
return new Response(stream, {
4343
headers: {
44+
'access-control-allow-origin': '*',
4445
'content-type': 'text/event-stream',
4546
'cache-control': 'no-cache',
4647
connection: 'keep-alive',
@@ -74,7 +75,7 @@ test('makes the actual request when called "server.connect()"', async ({
7475
await expect(openPromise).resolves.toBeUndefined()
7576
})
7677

77-
test('forwards message event from the server to the client automatically', async ({
78+
test.only('forwards message event from the server to the client automatically', async ({
7879
loadExample,
7980
page,
8081
}) => {
@@ -127,6 +128,8 @@ test('forwards message event from the server to the client automatically', async
127128
})
128129
}, url)
129130

131+
await page.pause()
132+
130133
expect(message).toEqual({ message: 'hello' })
131134
})
132135

0 commit comments

Comments
 (0)