using HTTP
using Colors
# initialize to nothing
orig_img = nothing
using ImageMagick
HTTP.listen() do http::HTTP.Stream
global orig_img
@show http.message
@show HTTP.header(http, "Content-Type")
while !eof(http)
orig_img = ImageMagick.readblob( readavailable(http))
end
end
orig_img
and then I curl an image to it by
curl -X POST --data-binary @"path/to/some.png" 127.0.0.1:8081
But the above the doesn’t seem to terminate even for a small image.
When I check orig_img it looks like the image got upload if a bit grainy.
But when I terminate curl everything dies with
julia> ┌ Error: (Base.IOError("read: connection reset by peer (ECONNRESET)", -4077), Base.StackTraces.StackFrame[wait_readnb(::Sockets.TCPSocket, ::Int64) at stream.jl:350, eof at stream.jl:48 [inlined], read_to_buffer(::HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}, ::Int64) at ConnectionPool.jl:251, readuntil(::HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}, ::Function, ::Int64) at ConnectionPool.jl:271, readuntil at ConnectionPool.jl:269 [inlined], readheaders at Messages.jl:471 [inlined], startread(::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}) at Streams.jl:155, handle_transaction(::var"#19#20", ::HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}, ::HTTP.Servers.Server{Nothing,Sockets.TCPServer}; final_transaction::Bool) at Servers.jl:343, (::HTTP.Servers.var"#handle_transaction##kw")(::NamedTuple{(:final_transaction,),Tuple{Bool}}, ::typeof(HTTP.Servers.handle_transaction), ::Function, ::HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}, ::HTTP.Servers.Server{Nothing,Sockets.TCPServer}) at Servers.jl:338, handle_connection(::Function, ::HTTP.ConnectionPool.Connection{Sockets.TCPSocket}, ::HTTP.Servers.Server{Nothing,Sockets.TCPServer}, ::Int64, ::Int64) at Servers.jl:299, (::HTTP.Servers.var"#8#9"{var"#19#20",HTTP.Servers.Server{Nothing,Sockets.TCPServer},Base.RefValue{Int64},Int64,Int64,Bool,HTTP.ConnectionPool.Connection{Sockets.TCPSocket}})() at task.jl:356])
I suspect I am just not understanding curl because I thought the image would have finished uploading and it will terminate.