Skip to content

Commit

Permalink
Attempt to fix #58 by making sure we read the entire body for request…
Browse files Browse the repository at this point in the history
…s that don't provide a content-length and we need to rely on the connection being closed to detect eof (#103)
  • Loading branch information
quinnj authored Oct 27, 2017
1 parent d6d42bc commit 697e3cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))"))
Expand Down
2 changes: 1 addition & 1 deletion src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 697e3cb

Please sign in to comment.