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 7E2641FE3F for ; Fri, 3 Jun 2016 01:28:09 +0000 (UTC) From: Eric Wong 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 Message-Id: <20160603012837.19143-2-e@80x24.org> In-Reply-To: <20160603012837.19143-1-e@80x24.org> References: <20160603012837.19143-1-e@80x24.org> List-Id: 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