Improve SSE endpoint sessionId parameter handling #177
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add dynamic query parameter separator for sessionId to handle endpoints with existing query parameters more robustly
This PR improves the URL construction when adding the sessionId parameter to endpoints by dynamically selecting the appropriate separator ('?' or '&') based on whether the endpoint already contains query parameters.
Motivation and Context
When constructing the endpoint URL with the sessionId parameter, the code needs to determine whether to use '?' or '&' as a separator. If the endpoint already contains query parameters (e.g.,
/messages?filter=all
), we should use '&' to append additional parameters. Otherwise, if there are no existing query parameters (e.g.,/messages
), we should use '?' to start the query string.This change ensures that the SSE endpoint URLs are correctly formed regardless of whether the original endpoint already contains query parameters, preventing malformed URLs in the SSE connection.
How Has This Been Tested?
Tested with various endpoint formats:
/messages
→/messages?sessionId=xxx
/messages?filter=all
→/messages?filter=all&sessionId=xxx
Breaking Changes
None. This is a non-breaking change that improves the robustness of URL handling without requiring any changes to user code.
Types of changes
Checklist
Additional context
The implementation uses a simple check for the presence of '?' in the endpoint string. While this approach works for standard endpoints, it has a limitation: it doesn't handle the edge case where '?' might be part of the path itself rather than a query parameter separator. However, this is an extremely rare case in practice, and the simplicity of the solution outweighs the benefit of handling such edge cases.