aboutsummaryrefslogtreecommitdiffstats
path: root/lib/webrick
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-28 08:05:52 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-28 08:05:52 +0000
commit2bdcd0bddea7de08b8845918ed27185fa3125734 (patch)
tree25b0ac66e5bf5f25402f1a71fec61248afd65b70 /lib/webrick
parentc44978b99f0454b8f00674f2f407893c8c47248e (diff)
downloadruby-2bdcd0bddea7de08b8845918ed27185fa3125734.tar.gz
webrick/httpresponse: IO.copy_stream for regular files
Remove the redundant _send_file method since its functionality is unnecessary with IO.copy_stream. IO.copy_stream also allows the use of sendfile under some OSes to speed up copies to non-TLS sockets. Testing with "curl >/dev/null" and "ruby -run -e httpd" to read a 1G file over Linux loopback reveals a reduction from around ~0.770 to ~0.490 seconds on the client side. * lib/webrick/httpresponse.rb (send_body_io): use IO.copy_stream (_send_file): remove [Feature #14237] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick')
-rw-r--r--lib/webrick/httpresponse.rb27
1 files changed, 3 insertions, 24 deletions
diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb
index eddd3388ed..82c53e60c7 100644
--- a/lib/webrick/httpresponse.rb
+++ b/lib/webrick/httpresponse.rb
@@ -410,9 +410,9 @@ module WEBrick
buf.clear
socket.write("0#{CRLF}#{CRLF}")
else
- size = @header['content-length'].to_i
- _send_file(socket, @body, 0, size)
- @sent_size = size
+ size = @header['content-length']
+ size = size.to_i if size
+ @sent_size = IO.copy_stream(@body, socket, size)
end
ensure
@body.close
@@ -474,27 +474,6 @@ module WEBrick
alias :<< :write
end
- def _send_file(output, input, offset, size)
- while offset > 0
- sz = @buffer_size < size ? @buffer_size : size
- buf = input.read(sz)
- offset -= buf.bytesize
- end
-
- if size == 0
- while buf = input.read(@buffer_size)
- output.write(buf)
- end
- else
- while size > 0
- sz = @buffer_size < size ? @buffer_size : size
- buf = input.read(sz)
- output.write(buf)
- size -= buf.bytesize
- end
- end
- end
-
# preserved for compatibility with some 3rd-party handlers
def _write_data(socket, data)
socket << data