Errors during handling of Keep-Alive connections
Hello there, I am forwarding an issue that we've been debugging with an OpenProject user and that (as far as I can judge) looks like an issue in the handling of Keep-Alive connections. ## Context OpenProject is using `httpx` internally to perform API requests to Nextcloud. The error report that we received is openly accessible at https://community.openproject.org/projects/nextcloud-integration/work_packages/69367/activity In the activity tab you can see us narrowing down the issue with the help of the affected user. Something that I have to admit upfront: I've not been able to reproduce the issue myself yet, therefore I also have no minimalized reproduction steps so far, though I'll post you once I can get them. I'll also link this issue here over at OpenProject, so that the affected user can answer themselves if you have additional questions to help with reproduction. I can also still help, but I am starting to dig into code that I barely understand, which is why I am raising this issue here as well, since you probably know your way around this much better than me. ## Symptoms HTTPX performs a successful HTTP request, but the second request performed by the same client raises ``` HTTPX::Parser::HTTP1#parse_headers': wrong header format (HTTPX::Parser::Error) from /app/vendor/bundle/ruby/3.4.0/gems/httpx-1.6.2/lib/httpx/parser/http1.rb:48:in 'block in HTTPX::Parser::HTTP1#parse' ``` The error is raised when reading this line: ``` HTTP/1.1 207 Multi-Status ``` Through some basic "puts debugging" we could find out that the `@buffer` contains the HTTP headline at the beginning of the call to `parse_headers`, when during usual parsing this should've already been removed at the end of `parse_headline`. We thus added another debug call to `parse_headline` and found that it wasn't called at all during the response that would later raise an error. Since there was a successful call before that, and I could see Keep-Alive response headers in the buffer, I had the suspicion that the `@state` could be messed up and thus the call of `parse_headline` could be skipped entirely. The affected user confirmed that disabling Keep-Alive apparently fixed the issue.
issue