Skip to content

Commit

Permalink
simplify Base.read!(::IO, ::Parser) per JuliaLang/MbedTLS.jl#114
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Dec 13, 2017
1 parent 4b601f5 commit fe07a9b
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/Parsers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,15 @@ Throws `ParsingError` if input is invalid.

function Base.read!(io::IO, p::Parser; unread=IOExtras.unread!)

while !eof(io)
while !messagecomplete(p) && !eof(io)
bytes = readavailable(io)
if isempty(bytes)
@debug 1 "Bug https://github.com/JuliaWeb/MbedTLS.jl/issues/113 !"
@assert isa(io, SSLContext)
@assert eof(io)
break
end

n = parse!(p, bytes)

if messagecomplete(p)
if n < length(bytes)
unread(io, view(bytes, n+1:length(bytes)))
end
return
if n < length(bytes)
unread(io, view(bytes, n+1:length(bytes)))
end
end

if !waitingforeof(p)
if eof(io) && !waitingforeof(p)
throw(ParsingError(headerscomplete(p) ? HPE_BODY_INCOMPLETE :
HPE_HEADERS_INCOMPLETE))
end
Expand Down

0 comments on commit fe07a9b

Please sign in to comment.