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 +1 -1
- data/lib/rack/proxy.rb +16 -14
- data/rack-proxy.gemspec +2 -2
- data/test/rack_proxy_test.rb +3 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/rack/proxy.rb
CHANGED
@@ -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(
|
9
|
+
rewrite_response(perform_request(rewrite_env(env)))
|
10
10
|
end
|
11
11
|
|
12
|
-
# Return
|
13
|
-
def
|
14
|
-
|
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(
|
24
|
+
def perform_request(env)
|
25
|
+
source_request = Rack::Request.new(env)
|
26
|
+
|
25
27
|
# Initialize request
|
26
|
-
|
28
|
+
target_request = Net::HTTP.const_get(source_request.request_method.capitalize).new(source_request.fullpath)
|
27
29
|
|
28
30
|
# Setup headers
|
29
|
-
|
31
|
+
target_request.initialize_http_header(extract_http_request_headers(source_request.env))
|
30
32
|
|
31
33
|
# Setup body
|
32
|
-
if
|
33
|
-
|
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
|
-
|
39
|
+
target_response = HttpStreamingResponse.new(target_request, source_request.host, source_request.port)
|
38
40
|
|
39
|
-
[
|
41
|
+
[target_response.status, target_response.headers, target_response.body]
|
40
42
|
end
|
41
43
|
|
42
|
-
def
|
43
|
-
headers =
|
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(/, +/) <<
|
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
|
data/rack-proxy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-proxy}
|
8
|
-
s.version = "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-
|
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 = [
|
data/test/rack_proxy_test.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2010-01-13 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|