Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# Usage:
def streaming
chunked_response do |resp|
resp.chunk do
"before" * 5000
end
resp.chunk do
sleep(1)
"\nsleeping...\n"
end
resp.chunk do
"after" * 1000
end
end
end
# Code:
class ChunkedResponse::Body
def initialize
@chunks = []
end
def chunk(&block)
@chunks << block
end
def each
@chunks.each do |chunk|
stuff = chunk.call
size = stuff.bytesize
if size > 0
yield [size.to_s(16), TERM, stuff, TERM].join
end
end
yield ["0", TERM, "", TERM].join
end
def size
0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.