From: normalperson@... Date: 2017-12-26T06:29:46+00:00 Subject: [ruby-core:84456] [Ruby trunk Feature#14237] [PATCH 0/2] webrick: use IO.copy_stream Issue #14237 has been reported by normalperson (Eric Wong). ---------------------------------------- Feature #14237: [PATCH 0/2] webrick: use IO.copy_stream https://bugs.ruby-lang.org/issues/14237 * Author: normalperson (Eric Wong) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- First patch is prepatory, second patch uses IO.copy_stream: https://80x24.org/spew/20171226043936.7694-1-e@80x24.org/raw https://80x24.org/spew/20171226043936.7694-2-e@80x24.org/raw It should support Content-Range in a 3rd (to-be-written) patch, too. [PATCH 2/2] 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 [PATCH 1/2] webrick: favor .write over << method This will make the next change to use IO.copy_stream easier-to-read. When we can drop Ruby 2.4 support in a few years, this will allow us to use writev(2) with multiple arguments for headers and chunked responses. * lib/webrick/cgi.rb (write): new wrapper method lib/webrick/httpresponse.rb (_write_data): remove (send_header): use socket.write (send_body_io): ditto (send_body_string): ditto (send_body_proc): ditto (ChunkedWrapper#write): ditto (_send_file): ditto -- https://bugs.ruby-lang.org/ Unsubscribe: