Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server response streaming early close #75

Closed
samoconnor opened this issue Aug 22, 2017 · 1 comment
Closed

Server response streaming early close #75

samoconnor opened this issue Aug 22, 2017 · 1 comment

Comments

@samoconnor
Copy link
Contributor

samoconnor commented Aug 22, 2017

I create a Server with a FIFOBuffer Response body.
I have an async task that writes data to the FIFOBuffer once per second forever.
Rather than the client receiving an infinite stream of data, it only gets the first line, after which the server closes the connection.

It looks like maybe Base.write(io::IO, r::Union{Request, Response} ...) should be doing while !eof(response.body) write(io, readavailable(response.body) end ?

Also, a content-length header is being returned even though the content is unknown (because the response FIFOBuffer has not been closed yet).

julia> server = HTTP.Server((req, rep) -> begin
           io = HTTP.FIFOBuffer()
           @async while true
               println(io, "data: $(now())\n")
               sleep(1)
           end
           r = Response(200, Dict(
           "Content-Type" => "text/event-stream",
           "Cache-Control" => "no-cache",
           "Connection" => "keep-alive"
       ), io)
       end, STDOUT)

julia> HTTP.serve(server)
$ curl 127.0.0.1:8081
data: 2017-08-22T22:00:04.988

$ curl 127.0.0.1:8081
data: 2017-08-22T22:00:05.635
@quinnj
Copy link
Member

quinnj commented Aug 22, 2017

Yeah, we definitely need to cleanup the response body handling server-side.

quinnj added a commit that referenced this issue Aug 23, 2017
…ome simplification in Request/Response writing. Fixes #75
@quinnj quinnj closed this as completed in 00425fd Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants