0
# Module that is mixed in to all implemented controllers.
0
+ def must_support_streaming!
0
+ raise(NotImplemented, "Current Rack adapter does not support streaming") unless request.env['rack.streaming']
0
# Renders the block given as a parameter using chunked
0
@@ -34,9 +36,11 @@ module Merb
0
# send chunks of data down to the server. The chunking will
0
# terminate once the block returns.
0
def render_chunked(&blk)
0
+ must_support_streaming!
0
headers['Transfer-Encoding'] = 'chunked'
0
- response.send_status_no_connection_close(0)
0
+ response.send_status_no_connection_close('')
0
response.write("0\r\n\r\n")
0
@@ -44,13 +48,14 @@ module Merb
0
# Writes a chunk from render_chunked to the response that
0
- # is sent back to the client.
0
+ # is sent back to the client. This can only be called within
0
+ # a render_chunked {} block
0
# data<String>:: a chunk of data to return
0
- response.write('%x' % data.size + "\r\n")
0
- response.write(data + "\r\n")
0
+ @response.write('%x' % data.size + "\r\n")
0
+ @response.write(data + "\r\n")
0
# Returns a +Proc+ that Mongrel can call later, allowing
0
@@ -61,7 +66,8 @@ module Merb
0
# A proc that should get called outside the mutex,
0
# and which will return the value to render
0
def render_deferred(&blk)
0
+ must_support_streaming!
0
response.send_status(result.length)
0
@@ -77,6 +83,7 @@ module Merb
0
# blk<Proc>:: A proc that should get called once the string has
0
def render_then_call(str, &blk)
0
+ must_support_streaming!
0
response.send_status(str.length)
0
@@ -111,10 +118,9 @@ module Merb
0
'Content-Type' => opts[:type].strip, # fixes a problem with extra '\r' with some browsers
0
'Content-Disposition' => disposition,
0
- 'Content-Transfer-Encoding' => 'binary',
0
+ 'Content-Transfer-Encoding' => 'binary'
0
# Streams a file over HTTP.
0
@@ -122,7 +128,7 @@ module Merb
0
# stream_file( { :filename => file_name,
0
# :type => content_type,
0
- # :content_length => content_length }) do
0
+ # :content_length => content_length }) do
|response|0
# AWS::S3::S3Object.stream(user.folder_name + "-" + user_file.unique_id, bucket_name) do |chunk|
0
@@ -140,6 +146,7 @@ module Merb
0
# :filename<String>:: An acceptable value for the filename= portion
0
# of headers["Content-Disposition"]
0
def stream_file(opts={}, &stream)
0
+ must_support_streaming!
0
opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts))
0
disposition = opts[:disposition].dup || 'attachment'
0
disposition << %(; filename="#{opts[:filename]}")
Comments
No one has commented yet.