yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH 1/3] req_res: store proxy_pass object here, instead
Date: Sun, 5 Jun 2016 22:53:14 +0000	[thread overview]
Message-ID: <20160605225314.GA8100@dcvr.yhbt.net> (raw)
In-Reply-To: <20160605225042.7861-2-e@80x24.org>

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
 

      parent reply	other threads:[~2016-06-05 22:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-05 22:50 [PATCH 2/3] proxy_pass: redo "proxy_buffering: false" Eric Wong
2016-06-05 22:50 ` [PATCH 3/3] wbuf: remove needless "busy" parameter Eric Wong
2016-06-05 22:53 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160605225314.GA8100@dcvr.yhbt.net \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    --subject='Re: [PATCH 1/3] req_res: store proxy_pass object here, instead' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	../../yahns.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).