Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/server/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ export class SSEServerTransport implements Transport {
});

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

this._sseResponse = this.res;
Expand Down