lib/reel/response.rb in reel-0.1.0 vs lib/reel/response.rb in reel-0.2.0.pre
- old
+ new
@@ -34,11 +34,11 @@
when IO
@headers['Content-Length'] ||= @body.stat.size
when Enumerable
@headers['Transfer-Encoding'] ||= 'chunked'
when NilClass
- else raise ArgumentError, "can't render #{@body.class} as a response body"
+ else raise TypeError, "can't render #{@body.class} as a response body"
end
# Prevent modification through the accessor
@headers.freeze
@@ -69,12 +69,16 @@
case @body
when String
socket << @body
when IO
- # TODO: IO.copy_stream when it works cross-platform
- while data = @body.read(4096)
- socket << data
+ if !defined?(JRUBY_VERSION)
+ IO.copy_stream(@body, socket)
+ else
+ # JRuby 1.6.7 doesn't support IO.copy_stream :(
+ while data = @body.read(4096)
+ socket << data
+ end
end
when Enumerable
@body.each do |chunk|
chunk_header = chunk.bytesize.to_s(16) + CRLF
socket << chunk_header