yahns Ruby server user/dev discussion
 help / color / Atom feed
* [PATCH] proxy_pass: X-Forwarded-For appends to existing list
@ 2016-05-31  4:18 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-05-31  4:18 UTC (permalink / raw)
  To: yahns-public

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-31  4:18 [PATCH] proxy_pass: X-Forwarded-For appends to existing list Eric Wong

yahns Ruby server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox