celluloid / reel

UNMAINTAINED: See celluloid/celluloid#779 - Celluloid::IO-powered web server
https://celluloid.io
MIT License
596 stars 87 forks source link

Streaming Transfer-Encoding: chunked responses requires writing to the Request instead of the Response #91

Open tarcieri opened 11 years ago

tarcieri commented 11 years ago

Reel's API to send streaming responses using chunked transfer encoding is still a bit wonky:

# Sending transfer_encoding chunked without a body enables streaming mode
request.respond :ok, :transfer_encoding => :chunked

# This will send individual chunks
request << "Hello"
request << "World"
request.finish_response # Write trailer and reset connection to header mode

It'd probably make more sense if we wrote to the response object instead of the request object:

response = Reel::Response.new(:ok, :transfer_encoding => :chunked)
request.respond response

response << "Hello"
response << "World"
response.finish