rack-proxy 0.5.9 → 0.5.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77cfbad861512cde3b7cfc42fb55dbdc5732ac54
4
- data.tar.gz: 41f8241e9bfea2cfec20820318c674ce2d5701bc
3
+ metadata.gz: 62bc77dceccd17a3c51368465f5e4559b1e2c10f
4
+ data.tar.gz: fa070a3fe2a3e8ba95372e5643601fcbcd2fa71d
5
5
  SHA512:
6
- metadata.gz: 8132a893c3345caf4d4a4e0b4d57bf978606c6e462e45848cc4199f20485d6e5735cd7d32f564038332ad5608b91b8ed602680eda690d9bf8602cdf3d71033f7
7
- data.tar.gz: 54496b618268e23ca229a7e8ce8a1a916991c4e2037c86bc47579faa9111adab18cf697e45db6cfbee5de35f2b25cb4e7ebf36857d7ff2361087d78c2fd045b9
6
+ metadata.gz: d4a4b8488144c9d46447112e97cef94113eb8487da3550d496d85fec159cd15ced276d210b07d64b88e4d3b3f4ab52b85c659a9d1d234ea666d9a9f4f360fa02
7
+ data.tar.gz: 7b1dc10788f6b5eb53f02612bed7066d971a7f12c2ec31215c3bec7f9d95de07c479841f756b8c56f6f509fc8a78891545deba4c7f44c7bba0a8c48a97812bd2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-proxy (0.5.9)
4
+ rack-proxy (0.5.10)
5
5
  rack
6
6
 
7
7
  GEM
data/lib/rack/proxy.rb CHANGED
@@ -5,7 +5,31 @@ module Rack
5
5
 
6
6
  # Subclass and bring your own #rewrite_request and #rewrite_response
7
7
  class Proxy
8
- VERSION = "0.5.9"
8
+ VERSION = "0.5.10"
9
+
10
+ class << self
11
+ def extract_http_request_headers(env)
12
+ headers = env.reject do |k, v|
13
+ !(/^HTTP_[A-Z_]+$/ === k) || v.nil?
14
+ end.map do |k, v|
15
+ [reconstruct_header_name(k), v]
16
+ end.inject(Utils::HeaderHash.new) do |hash, k_v|
17
+ k, v = k_v
18
+ hash[k] = v
19
+ hash
20
+ end
21
+
22
+ x_forwarded_for = (headers["X-Forwarded-For"].to_s.split(/, +/) << env["REMOTE_ADDR"]).join(", ")
23
+
24
+ headers.merge!("X-Forwarded-For" => x_forwarded_for)
25
+ end
26
+
27
+ protected
28
+
29
+ def reconstruct_header_name(name)
30
+ name.sub(/^HTTP_/, "").gsub("_", "-")
31
+ end
32
+ end
9
33
 
10
34
  # @option opts [String, URI::HTTP] :backend Backend host to proxy requests to
11
35
  def initialize(opts={})
@@ -43,7 +67,7 @@ module Rack
43
67
  target_request = Net::HTTP.const_get(source_request.request_method.capitalize).new(full_path)
44
68
 
45
69
  # Setup headers
46
- target_request.initialize_http_header(extract_http_request_headers(source_request.env))
70
+ target_request.initialize_http_header(self.class.extract_http_request_headers(source_request.env))
47
71
 
48
72
  # Setup body
49
73
  if target_request.request_body_permitted? && source_request.body
@@ -80,26 +104,6 @@ module Rack
80
104
  [target_response.code, headers, body]
81
105
  end
82
106
 
83
- def extract_http_request_headers(env)
84
- headers = env.reject do |k, v|
85
- !(/^HTTP_[A-Z_]+$/ === k) || v.nil?
86
- end.map do |k, v|
87
- [reconstruct_header_name(k), v]
88
- end.inject(Utils::HeaderHash.new) do |hash, k_v|
89
- k, v = k_v
90
- hash[k] = v
91
- hash
92
- end
93
-
94
- x_forwarded_for = (headers["X-Forwarded-For"].to_s.split(/, +/) << env["REMOTE_ADDR"]).join(", ")
95
-
96
- headers.merge!("X-Forwarded-For" => x_forwarded_for)
97
- end
98
-
99
- def reconstruct_header_name(name)
100
- name.sub(/^HTTP_/, "").gsub("_", "-")
101
- end
102
-
103
107
  end
104
108
 
105
109
  end
@@ -50,24 +50,24 @@ class RackProxyTest < Test::Unit::TestCase
50
50
  end
51
51
 
52
52
  def test_header_reconstruction
53
- proxy = Rack::Proxy.new
53
+ proxy_class = Rack::Proxy
54
54
 
55
- header = proxy.send(:reconstruct_header_name, "HTTP_ABC")
55
+ header = proxy_class.send(:reconstruct_header_name, "HTTP_ABC")
56
56
  assert header == "ABC"
57
57
 
58
- header = proxy.send(:reconstruct_header_name, "HTTP_ABC_D")
58
+ header = proxy_class.send(:reconstruct_header_name, "HTTP_ABC_D")
59
59
  assert header == "ABC-D"
60
60
  end
61
61
 
62
62
  def test_extract_http_request_headers
63
- proxy = Rack::Proxy.new
63
+ proxy_class = Rack::Proxy
64
64
  env = {
65
65
  'NOT-HTTP-HEADER' => 'test-value',
66
66
  'HTTP_ACCEPT' => 'text/html',
67
67
  'HTTP_CONNECTION' => nil
68
68
  }
69
69
 
70
- headers = proxy.send(:extract_http_request_headers, env)
70
+ headers = proxy_class.extract_http_request_headers(env)
71
71
  assert headers.key?('ACCEPT')
72
72
  assert !headers.key?('CONNECTION')
73
73
  assert !headers.key?('NOT-HTTP-HEADER')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacek Becela
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack