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 1034E1FE39 for ; Tue, 31 May 2016 04:18:03 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] proxy_pass: X-Forwarded-For appends to existing list Date: Tue, 31 May 2016 04:18:03 +0000 Message-Id: <20160531041803.15731-1-e@80x24.org> List-Id: Ugh, this is a little slower, but some people will want to forward through multiple proxies. --- lib/yahns/proxy_pass.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/yahns/proxy_pass.rb b/lib/yahns/proxy_pass.rb index 8e0b742..a30089d 100644 --- a/lib/yahns/proxy_pass.rb +++ b/lib/yahns/proxy_pass.rb @@ -59,9 +59,12 @@ def call(env) ver = 'HTTP/1.0'.freeze end + addr = env['REMOTE_ADDR'] + xff = env['HTTP_X_FORWARDED_FOR'] + xff = xff =~ /\S/ ? "#{xff}, #{addr}" : addr req = "#{env['REQUEST_METHOD']} #{req} #{ver}\r\n" \ "X-Forwarded-Proto: #{env['rack.url_scheme']}\r\n" \ - "X-Forwarded-For: #{env["REMOTE_ADDR"]}\r\n".dup + "X-Forwarded-For: #{xff}\r\n".dup # pass most HTTP_* headers through as-is chunked = false