From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH 1/2] proxy_pass: pass entire object to proxy_http_response
Date: Fri, 3 Jun 2016 01:28:36 +0000 [thread overview]
Message-ID: <20160603012837.19143-2-e@80x24.org> (raw)
In-Reply-To: <20160603012837.19143-1-e@80x24.org>
This will allow us to add extra options at the response
layer without taking up extra env hash keys.
---
lib/yahns/proxy_http_response.rb | 2 +-
lib/yahns/proxy_pass.rb | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index 284a3c6..c7a9447 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -71,7 +71,7 @@ def proxy_res_headers(res)
flags = MSG_DONTWAIT
alive = @hs.next? && self.class.persistent_connections
term = false
- response_headers = env['yahns.proxy_pass.response_headers']
+ response_headers = env['yahns.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 a30089d..ed37da5 100644
--- a/lib/yahns/proxy_pass.rb
+++ b/lib/yahns/proxy_pass.rb
@@ -10,6 +10,8 @@
require_relative 'req_res'
class Yahns::ProxyPass # :nodoc:
+ attr_reader :proxy_buffering, :response_headers
+
def initialize(dest, opts = {})
case dest
when %r{\Aunix:([^:]+)(?::(/.*))?\z}
@@ -23,6 +25,8 @@ def initialize(dest, opts = {})
raise ArgumentError, "destination must be an HTTP URL or unix: path"
end
@response_headers = opts[:response_headers] || {}
+ @proxy_buffering = opts[:proxy_buffering]
+ @proxy_buffering = true if @proxy_buffering.nil? # allow false
# It's wrong to send the backend Server tag through. Let users say
# { "Server => "yahns" } if they want to advertise for us, but don't
@@ -85,7 +89,7 @@ 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.response_headers'] = @response_headers
+ env['yahns.proxy_pass'] = self
# finally, prepare to emit the headers
rr.req_start(c, req << "\r\n".freeze, input, chunked)
--
EW
next prev parent reply other threads:[~2016-06-03 1:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-03 1:28 [PATCH 0/2] proxy_pass: allow disabling proxy buffering Eric Wong
2016-06-03 1:28 ` Eric Wong [this message]
2016-06-03 1:28 ` [PATCH 2/2] proxy_pass: support "proxy_buffering: false" Eric Wong
2016-06-03 1:58 ` [PATCH 3/2] proxy_pass: remove unnecessary rescue Eric Wong
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=20160603012837.19143-2-e@80x24.org \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/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).