Skip to content

Commit dad9eaf

Browse files
committed
Improve SSE endpoint sessionId parameter handling
Add dynamic query parameter separator for sessionId to handle endpoints with existing query parameters more robustly
1 parent 66e1508 commit dad9eaf

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/server/sse.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ export class SSEServerTransport implements Transport {
4949
});
5050

5151
// Send the endpoint event
52+
/**
53+
* Determine the appropriate separator for adding the sessionId parameter.
54+
* Uses '&' if the endpoint already contains a query parameter (has a '?'),
55+
* otherwise uses '?' to start the query string.
56+
*
57+
* Note: This approach works for standard endpoints but doesn't handle
58+
* the edge case where '?' might be part of the path itself.
59+
*/
60+
const separator = this._endpoint.includes('?') ? '&' : '?';
5261
this.res.write(
53-
`event: endpoint\ndata: ${encodeURI(this._endpoint)}?sessionId=${this._sessionId}\n\n`,
62+
`event: endpoint\ndata: ${encodeURI(this._endpoint)}${separator}sessionId=${this._sessionId}\n\n`,
5463
);
5564

5665
this._sseResponse = this.res;

0 commit comments

Comments
 (0)