rack-proxy 0.1.0 → 0.2.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.1.0
1
+ 0.2.0
@@ -6,12 +6,12 @@ module Rack
6
6
  # Subclass and bring your own #rewrite_request and #rewrite_response
7
7
  class Proxy
8
8
  def call(env)
9
- rewrite_response(perform_request(rewrite_request(Rack::Request.new(env))))
9
+ rewrite_response(perform_request(rewrite_env(env)))
10
10
  end
11
11
 
12
- # Return an instance of Rack::Request
13
- def rewrite_request(req)
14
- req
12
+ # Return modified env
13
+ def rewrite_env(env)
14
+ env
15
15
  end
16
16
 
17
17
  # Return a rack triplet [status, headers, body]
@@ -21,26 +21,28 @@ module Rack
21
21
 
22
22
  protected
23
23
 
24
- def perform_request(req)
24
+ def perform_request(env)
25
+ source_request = Rack::Request.new(env)
26
+
25
27
  # Initialize request
26
- http_request = Net::HTTP.const_get(req.request_method.capitalize).new(req.fullpath)
28
+ target_request = Net::HTTP.const_get(source_request.request_method.capitalize).new(source_request.fullpath)
27
29
 
28
30
  # Setup headers
29
- http_request.initialize_http_header(http_request_headers(req))
31
+ target_request.initialize_http_header(extract_http_request_headers(source_request.env))
30
32
 
31
33
  # Setup body
32
- if http_request.request_body_permitted? && req.body
33
- http_request.body_stream = req.body
34
+ if target_request.request_body_permitted? && req.body
35
+ target_request.body_stream = req.body
34
36
  end
35
37
 
36
38
  # Create a streaming response (the actual network communication is deferred, a.k.a. streamed)
37
- http_response = HttpStreamingResponse.new(http_request, req.host, req.port)
39
+ target_response = HttpStreamingResponse.new(target_request, source_request.host, source_request.port)
38
40
 
39
- [http_response.status, http_response.headers, http_response.body]
41
+ [target_response.status, target_response.headers, target_response.body]
40
42
  end
41
43
 
42
- def http_request_headers(req)
43
- headers = req.env.reject do |k, v|
44
+ def extract_http_request_headers(env)
45
+ headers = env.reject do |k, v|
44
46
  !(/^HTTP_[A-Z_]+$/ === k)
45
47
  end.map do |k, v|
46
48
  [k.sub(/^HTTP_/, ""), v]
@@ -50,7 +52,7 @@ module Rack
50
52
  hash
51
53
  end
52
54
 
53
- x_forwarded_for = (headers["X-Forwarded-For"].to_s.split(/, +/) << req.env["REMOTE_ADDR"]).join(", ")
55
+ x_forwarded_for = (headers["X-Forwarded-For"].to_s.split(/, +/) << env["REMOTE_ADDR"]).join(", ")
54
56
 
55
57
  headers.merge!("X-Forwarded-For" => x_forwarded_for)
56
58
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-proxy}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.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"]
12
- s.date = %q{2010-01-08}
12
+ s.date = %q{2010-01-13}
13
13
  s.description = %q{A Rack app that provides request/response rewriting proxy capabilities with streaming.}
14
14
  s.email = %q{jacek.becela@gmail.com}
15
15
  s.files = [
@@ -3,10 +3,10 @@ require "rack/proxy"
3
3
 
4
4
  class RackProxyTest < Test::Unit::TestCase
5
5
  class TrixProxy < Rack::Proxy
6
- def rewrite_request(req)
7
- req.env["HTTP_HOST"] = "trix.pl"
6
+ def rewrite_env(env)
7
+ env["HTTP_HOST"] = "trix.pl"
8
8
 
9
- req
9
+ env
10
10
  end
11
11
  end
12
12
 
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacek Becela
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-08 00:00:00 +01:00
12
+ date: 2010-01-13 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency