diff --git a/src/client.jl b/src/client.jl index fe1daa167..ecdb1fb1e 100644 --- a/src/client.jl +++ b/src/client.jl @@ -271,6 +271,7 @@ function getbytes(socket, tm) buffer = @retry @timeout(tm, readavailable(socket), error("read timeout")) return buffer, CLOSED_ERROR catch e + isa(e, InterruptException) && throw(e) return UInt8[], ReadError(e, backtrace()) end end @@ -279,16 +280,17 @@ function processresponse!(client, conn, response, host, method, maintask, stream logger = client.logger while true buffer, err = getbytes(conn.socket, tm) - if length(buffer) == 0 && !isopen(conn.socket) + @log "received bytes from the wire, processing" + # EH: throws a couple of "shouldn't get here" errors; probably not much we can do + errno, headerscomplete, messagecomplete, upgrade = HTTP.parse!(response, client.parser, buffer; host=host, method=method, maintask=maintask, canonicalizeheaders=canonicalizeheaders) + @log "parsed bytes received from wire" + if length(buffer) == 0 && !isopen(conn.socket) && !messagecomplete @log "socket closed before full response received" dead!(conn) close(response.body) # retry the entire request return false, err end - @log "received bytes from the wire, processing" - # EH: throws a couple of "shouldn't get here" errors; probably not much we can do - errno, headerscomplete, messagecomplete, upgrade = HTTP.parse!(response, client.parser, buffer; host=host, method=method, maintask=maintask, canonicalizeheaders=canonicalizeheaders) if errno != HPE_OK dead!(conn) throw(ParsingError("error parsing response: $(ParsingErrorCodeMap[errno])\nCurrent response buffer contents: $(String(buffer))")) diff --git a/src/parser.jl b/src/parser.jl index 6f206b4c9..55cac9aca 100644 --- a/src/parser.jl +++ b/src/parser.jl @@ -1311,7 +1311,7 @@ function parse!(r, parser, bytes, len, lenient, host, method, maxuri, maxheader, @debug(PARSING_DEBUG, ParsingStateCode(p_state)) b = p_state == start_state || p_state == s_dead he = b | (headersdone || p_state >= s_headers_done) - m = b | (p_state >= s_body_identity_eof) + m = b | (p_state >= s_message_done) return errno, he, m, String(bytes[p:end]) @label error