From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 238191FEA4; Sun, 5 Jun 2016 22:53:14 +0000 (UTC) Date: Sun, 5 Jun 2016 22:53:14 +0000 From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH 1/3] req_res: store proxy_pass object here, instead Message-ID: <20160605225314.GA8100@dcvr.yhbt.net> References: <20160605225042.7861-2-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160605225042.7861-2-e@80x24.org> List-Id: We cannot rely on env being available after proxy_wait_next --- Oops, fat-fingered sending the mail :x Correct patch order should be: req_res: store proxy_pass object here, instead proxy_pass: redo "proxy_buffering: false" wbuf: remove needless "busy" parameter lib/yahns/proxy_http_response.rb | 4 ++-- lib/yahns/proxy_pass.rb | 3 +-- lib/yahns/req_res.rb | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index 2968062..765fe14 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -27,7 +27,7 @@ def proxy_write(wbuf, buf, req_res) when String, Array # partial write, hope the skb grows buf = rv when :wait_writable, :wait_readable - if @hs.env['yahns.proxy_pass'].proxy_buffering + if req_res.proxy_pass.proxy_buffering body = nil alive = req_res.alive else @@ -88,7 +88,7 @@ def proxy_res_headers(res, req_res) flags = MSG_DONTWAIT alive = @hs.next? && self.class.persistent_connections term = false - response_headers = env['yahns.proxy_pass'].response_headers + response_headers = req_res.proxy_pass.response_headers res = "HTTP/1.1 #{msg ? %Q(#{code} #{msg}) : status}\r\n".dup headers.each do |key,value| # n.b.: headers is an Array of 2-element Arrays diff --git a/lib/yahns/proxy_pass.rb b/lib/yahns/proxy_pass.rb index ed37da5..fcd0cf7 100644 --- a/lib/yahns/proxy_pass.rb +++ b/lib/yahns/proxy_pass.rb @@ -89,10 +89,9 @@ def call(env) ctype = env["CONTENT_TYPE"] and req << "Content-Type: #{ctype}\r\n" clen = env["CONTENT_LENGTH"] and req << "Content-Length: #{clen}\r\n" input = chunked || (clen && clen.to_i > 0) ? env['rack.input'] : nil - env['yahns.proxy_pass'] = self # finally, prepare to emit the headers - rr.req_start(c, req << "\r\n".freeze, input, chunked) + rr.req_start(c, req << "\r\n".freeze, input, chunked, self) # this probably breaks fewer middlewares than returning whatever else... [ 500, [], [] ] diff --git a/lib/yahns/req_res.rb b/lib/yahns/req_res.rb index dd4ec87..f585bd9 100644 --- a/lib/yahns/req_res.rb +++ b/lib/yahns/req_res.rb @@ -11,12 +11,14 @@ class Yahns::ReqRes < Kgio::Socket # :nodoc: attr_writer :paused attr_accessor :proxy_trailers attr_accessor :alive + attr_reader :proxy_pass - def req_start(c, req, input, chunked) + def req_start(c, req, input, chunked, proxy_pass) @hdr = @resbuf = nil @yahns_client = c @paused = false @rrstate = input ? [ req, input, chunked ] : req + @proxy_pass = proxy_pass Thread.current[:yahns_queue].queue_add(self, Yahns::Queue::QEV_WR) end