Skip to content

Commit

Permalink
Merge pull request #346 from JuliaWeb/issue_344
Browse files Browse the repository at this point in the history
fix #344 and #343
  • Loading branch information
samoconnor authored Dec 18, 2018
2 parents a383583 + e0fbc89 commit a916dd1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/ConnectionRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function request(::Type{ConnectionPoolLayer{Next}}, url::URI, req, body;
rethrow(isioerror(e) ? IOError(e, "during request($url)") : e)
end

if io.sequence >= reuse_limit
defaultheader(req, "Connection" => "close")
end

try
if proxy !== nothing && target_url.scheme == "https"
return tunnel_request(Next, io, target_url, req, body; kw...)
Expand All @@ -56,7 +60,7 @@ function request(::Type{ConnectionPoolLayer{Next}}, url::URI, req, body;
close(io)
rethrow(isioerror(e) ? IOError(e, "during request($url)") : e)
finally
if (reuse_limit == 0
if (io.sequence >= reuse_limit
|| (proxy !== nothing && target_url.scheme == "https"))
close(io)
end
Expand Down
27 changes: 15 additions & 12 deletions src/Streams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,24 @@ incomplete(http::Stream) =

function IOExtras.closeread(http::Stream{Response})

# Discard body bytes that were not read...
while !eof(http)
readavailable(http)
end

if incomplete(http)
# Error if Message is not complete...
close(http.stream)
throw(EOFError())
elseif hasheader(http.message, "Connection", "close")
if hasheader(http.message, "Connection", "close")
# Close conncetion if server sent "Connection: close"...
@debug 1 "\"Connection: close\": $(http.stream)"
close(http.stream)
elseif isreadable(http.stream)
closeread(http.stream)
else

# Discard body bytes that were not read...
while !eof(http)
readavailable(http)
end

if incomplete(http)
# Error if Message is not complete...
close(http.stream)
throw(EOFError())
elseif isreadable(http.stream)
closeread(http.stream)
end
end

return http.message
Expand Down

0 comments on commit a916dd1

Please sign in to comment.