diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-12-30 08:32:26 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-01-04 16:21:17 -0800 |
commit | c38bc88363d4c4f5f639540ca86f4dd1225df79e (patch) | |
tree | 97d039d48177dc571d81a224437dffc7d44045de /lib/rainbows/response/body.rb | |
parent | 1a03f9a525faf4c997546c419de6854223b645c4 (diff) | |
download | rainbows-c38bc88363d4c4f5f639540ca86f4dd1225df79e.tar.gz |
Unique method names makes it easier to follow code and determine where our methods come from.
Diffstat (limited to 'lib/rainbows/response/body.rb')
-rw-r--r-- | lib/rainbows/response/body.rb | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/lib/rainbows/response/body.rb b/lib/rainbows/response/body.rb index e80217d..a5d04dd 100644 --- a/lib/rainbows/response/body.rb +++ b/lib/rainbows/response/body.rb @@ -58,26 +58,28 @@ module Rainbows::Response::Body # :nodoc: end if IO.method_defined?(:sendfile_nonblock) - def write_body_file(sock, body, range) + def write_body_file_sendfile(sock, body, range) io = body_to_io(body) range ? sock.sendfile(io, range[0], range[1]) : sock.sendfile(io, 0) ensure close_if_private(io) end + ALIASES[:write_body_file] = :write_body_file_sendfile end if IO.respond_to?(:copy_stream) - unless method_defined?(:write_body_file) + unless method_defined?(:write_body_file_sendfile) # try to use sendfile() via IO.copy_stream, otherwise pread()+write() - def write_body_file(sock, body, range) + def write_body_file_copy_stream(sock, body, range) range ? IO.copy_stream(body, sock, range[1], range[0]) : IO.copy_stream(body, sock, nil, 0) end + ALIASES[:write_body_file] = :write_body_file_copy_stream end # only used when body is a pipe or socket that can't handle # pread() semantics - def write_body_stream(sock, body, range) + def write_body_stream(sock, body) IO.copy_stream(body, sock) end else @@ -85,18 +87,11 @@ module Rainbows::Response::Body # :nodoc: ALIASES[:write_body_stream] = :write_body_each end - if method_defined?(:write_body_file) + if ALIASES[:write_body_file] # middlewares/apps may return with a body that responds to +to_path+ def write_body_path(sock, body, range) - stat = File.stat(body.to_path) - stat.file? ? write_body_file(sock, body, range) : - write_body_stream(sock, body, range) - ensure - body.respond_to?(:close) and body.close - end - elsif method_defined?(:write_body_stream) - def write_body_path(sock, body, range) - write_body_stream(sock, body, range) + File.file?(body.to_path) ? write_body_file(sock, body, range) : + write_body_stream(sock, body) ensure body.respond_to?(:close) and body.close end @@ -106,7 +101,7 @@ module Rainbows::Response::Body # :nodoc: def write_body(client, body, range) body.respond_to?(:to_path) ? write_body_path(client, body, range) : - write_body_each(client, body, range) + write_body_each(client, body) end else ALIASES[:write_body] = :write_body_each |