diff options
-rwxr-xr-x | GIT-VERSION-GEN | 6 | ||||
-rw-r--r-- | extras/exec_cgi.rb | 7 | ||||
-rw-r--r-- | lib/yahns/http_client.rb | 2 | ||||
-rw-r--r-- | lib/yahns/proxy_http_response.rb | 10 | ||||
-rw-r--r-- | lib/yahns/req_res.rb | 6 | ||||
-rw-r--r-- | test/test_buffer_tmpdir.rb | 2 | ||||
-rw-r--r-- | test/test_extras_exec_cgi.rb | 3 | ||||
-rw-r--r-- | test/test_ssl.rb | 2 | ||||
-rw-r--r-- | yahns.gemspec | 4 |
9 files changed, 24 insertions, 18 deletions
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index e758224..31e49e7 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,11 +1,11 @@ #!/usr/bin/env ruby -# Copyright (C) 2013-2019 all contributors <yahns-public@yhbt.net> -# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt) +# Copyright (C) all contributors <yahns-public@yhbt.net> +# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true CONSTANT = "Yahns::VERSION" RVF = "lib/yahns/version.rb" GVF = "GIT-VERSION-FILE" -DEF_VER = "v1.17.0" +DEF_VER = "v1.18.0" vn = DEF_VER.dup # First see if there is a version file (included in release tarballs), diff --git a/extras/exec_cgi.rb b/extras/exec_cgi.rb index 8a1939d..a04087d 100644 --- a/extras/exec_cgi.rb +++ b/extras/exec_cgi.rb @@ -34,14 +34,15 @@ class ExecCgi def each buf = @body_tip yield buf unless buf.empty? + buf = @body_tip = nil - case tmp = @rd.read_nonblock(8192, buf, exception: false) + case tmp = @rd.read_nonblock(8192, exception: false) when :wait_readable @rd.wait_readable when nil break else # String - yield tmp + yield tmp.freeze end while true self ensure @@ -117,7 +118,7 @@ class ExecCgi tmp.clear end head, body = head.split(/\r?\n\r?\n/, 2) - io.body_tip = body + io.body_tip = body.freeze env["HTTP_VERSION"] ||= "HTTP/1.0" # stop Rack::Chunked for HTTP/0.9 diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb index b6b6035..826eb8d 100644 --- a/lib/yahns/http_client.rb +++ b/lib/yahns/http_client.rb @@ -315,7 +315,7 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc: end def do_pread(io, count, offset) - count = 0x4000 if count > 0x4000 + count = 16384 if count > 16384 buf = Thread.current[:yahns_sfbuf] ||= ''.dup if io.respond_to?(:pread) io.pread(count, offset, buf) diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index 7df2834..db9c4b7 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -146,6 +146,12 @@ module Yahns::HttpResponse # :nodoc: have_body end + def read_len(len) + max = 16384 + max = len if len && len < max + max + end + def proxy_read_body(tip, kcar, req_res) chunk = ''.dup if kcar.chunked? len = kcar.body_bytes_left @@ -153,7 +159,7 @@ module Yahns::HttpResponse # :nodoc: alive = req_res.alive wbuf = req_res.resbuf - case tmp = tip.shift || req_res.kgio_tryread(0x2000, rbuf) + case tmp = tip.shift || req_res.kgio_tryread(read_len(len), rbuf) when String if len kcar.body_bytes_left -= tmp.size # progress for body_eof? => true @@ -200,7 +206,7 @@ module Yahns::HttpResponse # :nodoc: wbuf = req_res.resbuf until kcar.trailers(tlr, chunk) - case rv = req_res.kgio_tryread(0x2000, rbuf) + case rv = req_res.kgio_tryread(16384, rbuf) when String chunk << rv when :wait_readable diff --git a/lib/yahns/req_res.rb b/lib/yahns/req_res.rb index 4ad8e5c..283fea8 100644 --- a/lib/yahns/req_res.rb +++ b/lib/yahns/req_res.rb @@ -29,7 +29,7 @@ class Yahns::ReqRes < Kgio::Socket # :nodoc: case resbuf = @resbuf # where are we at the response? when nil # common case, catch the response header in a single read - case rv = kgio_tryread(0x2000, buf) + case rv = kgio_tryread(16384, buf) when String if res = req.headers(@hdr = [], rv) return c.proxy_response_start(res, rv, req, self) @@ -48,7 +48,7 @@ class Yahns::ReqRes < Kgio::Socket # :nodoc: when String # continue reading trickled response headers from upstream - case rv = kgio_tryread(0x2000, buf) + case rv = kgio_tryread(16384, buf) when String then res = req.headers(@hdr, resbuf << rv) and break when :wait_readable then return rv when nil @@ -114,7 +114,7 @@ class Yahns::ReqRes < Kgio::Socket # :nodoc: # we should not be waiting on a slow network resource when reading # input. However, some weird configs may disable this on LANs # and we may wait indefinitely on input.read here... - while input.read(0x2000, rbuf) + while input.read(16384, rbuf) if chunked buf[0] = "#{rbuf.size.to_s(16)}\r\n".freeze buf[1] = rbuf diff --git a/test/test_buffer_tmpdir.rb b/test/test_buffer_tmpdir.rb index bac8017..39029ed 100644 --- a/test/test_buffer_tmpdir.rb +++ b/test/test_buffer_tmpdir.rb @@ -67,7 +67,6 @@ class TestBufferTmpdir < Testcase event = @ino.take assert_equal [:DELETE], event.events assert_equal name, event.name - refute File.exist?("#@tmpdir/#{name}") end ensure c.close if c @@ -101,7 +100,6 @@ class TestBufferTmpdir < Testcase event = ino.take assert_equal [:DELETE], event.events assert_equal name, event.name - refute File.exist?("#{tmpdir}/#{name}") end ensure c.close if c diff --git a/test/test_extras_exec_cgi.rb b/test/test_extras_exec_cgi.rb index 426409d..4fa928d 100644 --- a/test/test_extras_exec_cgi.rb +++ b/test/test_extras_exec_cgi.rb @@ -136,7 +136,7 @@ class TestExtrasExecCGI < Testcase Yahns::HttpClient.__send__(:include, TrywriteBlocked) require './extras/exec_cgi' cfg.instance_eval do - stack = Rack::ContentLength.new(Rack::Chunked.new(ExecCgi.new(RUNME))) + stack = Rack::Chunked.new(ExecCgi.new(RUNME)) app(:rack, stack) { listen "#{host}:#{port}" } stderr_path err.path worker_processes 1 @@ -170,6 +170,7 @@ class TestExtrasExecCGI < Testcase assert_match %r{\A\d+\n\z}, body exec_pid = body.to_i poke_until_dead exec_pid + # lack of Content-Length should trigger EOF here: assert_raises(EOFError) { c.readpartial(666) } else raise "BUG in test, bad rtype" diff --git a/test/test_ssl.rb b/test/test_ssl.rb index 7909094..9442ec8 100644 --- a/test/test_ssl.rb +++ b/test/test_ssl.rb @@ -178,7 +178,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC s.any_old_invalid_test_method s.puts "FAIL" rescue => e - s.puts "#{e.class}: #{e.message}" + s.puts("#{e.class}: #{e.message}".split("\n")[0]) end when nil s.close diff --git a/yahns.gemspec b/yahns.gemspec index 3808061..8eb9a3d 100644 --- a/yahns.gemspec +++ b/yahns.gemspec @@ -1,5 +1,5 @@ -# Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net> -# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt) +# Copyright (C) all contributors <yahns-public@yhbt.net> +# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> Gem::Specification.new do |s| manifest = File.read('.gem-manifest').split(/\n/) s.name = %q{yahns} |