diff options
Diffstat (limited to 'lib/yahns/proxy_http_response.rb')
-rw-r--r-- | lib/yahns/proxy_http_response.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index d9c878e..9f75fec 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -1,7 +1,7 @@ # -*- encoding: binary -*- # Copyright (C) 2015-2016 all contributors <yahns-public@yhbt.net> # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt) -# frozen_string_literal: true +# frozen_string_literal: false require_relative 'wbuf_lite' @@ -31,9 +31,9 @@ module Yahns::HttpResponse # :nodoc: def proxy_write(wbuf, buf, req_res) unless wbuf # no write buffer, try to write directly to the client socket - case rv = String === buf ? kgio_trywrite(buf) : kgio_trywritev(buf) + case rv = kgio_trywrite(buf) when nil then return # done writing buf, likely - when String, Array # partial write, hope the skb grows + when String # partial write, hope the skb grows buf = rv when :wait_writable, :wait_readable wbuf = req_res.resbuf ||= wbuf_alloc(req_res) @@ -157,16 +157,18 @@ module Yahns::HttpResponse # :nodoc: when String if len kcar.body_bytes_left -= tmp.size # progress for body_eof? => true + clr = nil elsif chunk kcar.filter_body(chunk, rbuf = tmp) # progress for body_eof? => true next if chunk.empty? # call req_res.read_nonblock for more - tmp = chunk_out(chunk) + clr = tmp = chunk_out(chunk) + chunk.clear elsif alive # HTTP/1.0 upstream, HTTP/1.1 client - tmp = chunk_out(tmp) + clr = tmp = chunk_out(tmp) # else # HTTP/1.0 upstream, HTTP/1.0 client, do nothing end wbuf = proxy_write(wbuf, tmp, req_res) - chunk.clear if chunk + clr.clear if clr if Yahns::WbufLite === wbuf req_res.proxy_trailers = [ rbuf.dup, tip ] if chunk && kcar.body_eof? return proxy_unbuffer(wbuf) @@ -296,7 +298,7 @@ module Yahns::HttpResponse # :nodoc: # of String#bytesize because all the IO read methods return a binary # string when given a maximum read length def chunk_out(buf) - [ "#{buf.size.to_s(16)}\r\n", buf, "\r\n".freeze ] + "#{buf.size.to_s(16)}\r\n#{buf}\r\n" end def trailer_out(tlr) |