Skip to content

Commit

Permalink
handle multiple Transfer-Encoding headers and/or multiple values, e.g…
Browse files Browse the repository at this point in the history
…. "gzip, chunked"
  • Loading branch information
samoconnor committed Jan 18, 2018
1 parent 17b8cd7 commit f9837eb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ end
Does the `Message` have a "Transfer-Encoding: chunked" header?
"""

ischunked(m) = hasheader(m, "Transfer-Encoding", "chunked")
ischunked(m) = any(h->(lowercase(h[1]) == "transfer-encoding" &&
endswith(lowercase(h[2]), "chunked")),
m.headers)


"""
Expand Down Expand Up @@ -394,14 +396,19 @@ end
#Like https://github.com/JuliaIO/FileIO.jl/blob/v0.6.1/src/FileIO.jl#L19 ?
load(m::Message) = payload(m, String)

payload(m::Message)::Vector{UInt8} =
(enc = header(m, "Transfer-Encoding")) != "" ? decode(m, enc) : m.body
function payload(m::Message)::Vector{UInt8}
enc = lowercase(first(split(header(m, "Transfer-Encoding"), ", ")))
return enc in ["", "identity", "chunked"] ? m.body : decode(m, enc)
end

payload(m::Message, ::Type{String}) =
hasheader(m, "Content-Type", "ISO-8859-1") ? iso8859_1_to_utf8(payload(m)) :
String(payload(m))

function decode(m::Message, encoding::String)::Vector{UInt8}
if enc == "gzip"
# Use https://github.com/bicycle1885/TranscodingStreams.jl ?
end
@warn "Decoding of HTTP Transfer-Encoding is not implemented yet!"
return m.body
end
Expand Down

0 comments on commit f9837eb

Please sign in to comment.