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 CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -9,7 +9,7 @@ module Rack
9
9
  end
10
10
 
11
11
  def status
12
- response.code
12
+ response.code.to_i
13
13
  end
14
14
 
15
15
  def headers
@@ -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
- def rewrite_response(res)
17
- res
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({}) do |hash, k_v|
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-proxy}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jacek Becela"]
@@ -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 == "200"
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
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacek Becela