Hi, This is a bug report for url.el, more specifically for url-http.el in the context of processing responses with Transfer-Encoding set to "chunked". As per [0], the last chunk of 0 bytes is always accompanied by a last CRLF that signals the end of the message: chunked-body = *chunk last-chunk trailer-part CRLF ^ this one chunk = chunk-size [ chunk-ext ] CRLF chunk-data CRLF chunk-size = 1*HEXDIG last-chunk = 1*("0") [ chunk-ext ] CRLF chunk-data = 1*OCTET ; a sequence of chunk-size octets `url-http-chunked-encoding-after-change-function' is able to process (and remove) that terminator IF AVAILABLE in the buffer when processing the response, however it won't wait for it if it's not yet there. In other words: | Bottom of the response buffer | Bottom of the full response | | (visible to url-http) | (to be delivered to Emacs) | | ------------------------------+-----------------------------| | 0\r\n | 0\r\n | | | \r\n | If the last chunk is processed when the bottom of the response buffer is as above (note that the whole response has not yet been delivered to Emacs), url-http will call the user callback without waiting for the final terminator to be read from the socket. This is normally not an issue when doing one-shot requests, but it's problematic when the connection is reused immediately. As there are 2 bytes from the request N that have not been dealt with, they'll be considered as part of the response of the request N+1. On top, it turns out that when processing the headers of request N+1, `url-http-wait-for-headers-change-function' will consider the request a "headerless malformed response" (due to the leading \r\n) delivering it broken to the caller. I'm attaching a patch that I've got applied locally that prevents the problem from happening by implementing an extra state in which `url-http-chunked-encoding-after-change-function` properly waits for the very last element of the message. Unfortunately my copyright papers are stuck on the FSF for months now so I'm unable to submit a patch directly myself so feel free to use the attached diff as a PoC to illustrate the nature of the problem and a possible fix. A more experienced Elisp developer will surely find a more elegant solution. Please note that the patch sits on top of the emacs-28 branch. For additional context, this bug was found when debugging magit/ghub (see [1] for details). Hope this helps. [0] https://datatracker.ietf.org/doc/html/rfc7230#section-4.1 [1] https://github.com/magit/ghub/issues/81