-
Notifications
You must be signed in to change notification settings - Fork 56
Fix event stream line parsing to handle CRLF and empty lines correctly #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix event stream line parsing to handle CRLF and empty lines correctly #89
Conversation
…ue of `AsyncSequence` to produce a `AsyncLineSequence` instead of building a lines manually.
Nice! That sounds like a totally reasonable optimization. Thanks so much for sharing it. I kicked off a CI build. Should get a chance to review it in depth over the weekend. |
I def like the code change but checked out the branch and tested and it doesn't seem to be detecting the empty line that the code needs to dispatch notifications. I can only assume it works for you but for me line 225 is never catching so the client isn't getting the notes, where it did before going byte at a time. |
- Fiexed original issue I experienced with line 229 `while let newlineIndex = buffer.firstIndex(of: "\n") {` not handling "\r\n" properly - Added unit test to test for "\r\n" scenario - Simplified `end of event` test - `line` creation trims newline, added code trims carriage return. Only thing that should be left is an empty line
Apologies, I jumped the gun in submitting this PR. The core issue I experienced was that line 229 I've updated the code to |
@aspitz Thank you! Yeah, its annoying and we have run into that before. We have MCP servers running in python that return different line endings than the ones we have running in node+typescript, CRLF vs CRLF+CRLF. |
@aspitz @stallent Good morning! Thank you both for looking into this. I started to write a reply, but waited too long and y'all beat me to it.
Taking a fresh look at this now 😄 |
@mattt if you take this, i'll resolve any merge conflicts with my minimal fix to get streamable htttp client working with latest servers. Still think we have larger api chats around that, but hopefully the modest current PR (vs the too big of one i was pursuing) will unblock us until further chats can be had. |
connectToEventStream
This is looking good. Thank you again, @aspitz, for your work on this. I just updated the PR to reflect the final changes, and will merge this shortly. |
Optimized code in
connectToEventStream
to use.lines
computed value ofAsyncSequence
to produce aAsyncLineSequence
instead of building a lines manually.Motivation and Context
How Has This Been Tested?
Breaking Changes
No
Types of changes
Checklist
Additional context