rack-proxy 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rack/http_streaming_response.rb +1 -1
- data/lib/rack/proxy.rb +10 -4
- data/rack-proxy.gemspec +1 -1
- data/test/http_streaming_response_test.rb +1 -2
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/rack/proxy.rb
CHANGED
@@ -9,12 +9,14 @@ module Rack
|
|
9
9
|
rewrite_response(perform_request(rewrite_request(Rack::Request.new(env))))
|
10
10
|
end
|
11
11
|
|
12
|
+
# Return an instance of Rack::Request
|
12
13
|
def rewrite_request(req)
|
13
14
|
req
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
# Return a rack triplet [status, headers, body]
|
18
|
+
def rewrite_response(triplet)
|
19
|
+
triplet
|
18
20
|
end
|
19
21
|
|
20
22
|
protected
|
@@ -38,15 +40,19 @@ module Rack
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def http_request_headers(req)
|
41
|
-
req.env.reject do |k, v|
|
43
|
+
headers = req.env.reject do |k, v|
|
42
44
|
!(/^HTTP_[A-Z_]+$/ === k)
|
43
45
|
end.map do |k, v|
|
44
46
|
[k.sub(/^HTTP_/, ""), v]
|
45
|
-
end.inject(
|
47
|
+
end.inject(Utils::HeaderHash.new) do |hash, k_v|
|
46
48
|
k, v = k_v
|
47
49
|
hash[k] = v
|
48
50
|
hash
|
49
51
|
end
|
52
|
+
|
53
|
+
x_forwarded_for = (headers["X-Forwarded-For"].to_s.split(/, +/) << req.env["REMOTE_ADDR"]).join(", ")
|
54
|
+
|
55
|
+
headers.merge!("X-Forwarded-For" => x_forwarded_for)
|
50
56
|
end
|
51
57
|
|
52
58
|
end
|
data/rack-proxy.gemspec
CHANGED
@@ -9,7 +9,7 @@ class HttpStreamingResponseTest < Test::Unit::TestCase
|
|
9
9
|
response = Rack::HttpStreamingResponse.new(req, host)
|
10
10
|
|
11
11
|
# Response status
|
12
|
-
assert response.status ==
|
12
|
+
assert response.status == 200
|
13
13
|
|
14
14
|
# Headers
|
15
15
|
headers = response.headers
|
@@ -32,4 +32,3 @@ class HttpStreamingResponseTest < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
end
|
35
|
-
|