rack-reverse-proxy 0.2.0 → 0.3.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/reverse_proxy.rb +12 -7
- data/rack-reverse-proxy.gemspec +4 -5
- metadata +4 -6
- data/README +0 -26
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/rack/reverse_proxy.rb
CHANGED
@@ -21,22 +21,27 @@ module Rack
|
|
21
21
|
end
|
22
22
|
}
|
23
23
|
|
24
|
-
|
24
|
+
Net::HTTP.start(uri.host, uri.port) { |http|
|
25
25
|
m = rackreq.request_method
|
26
26
|
case m
|
27
27
|
when "GET", "HEAD", "DELETE", "OPTIONS", "TRACE"
|
28
|
-
req = Net::HTTP.const_get(m.capitalize).new(uri.
|
28
|
+
req = Net::HTTP.const_get(m.capitalize).new(uri.request_uri, headers)
|
29
29
|
when "PUT", "POST"
|
30
|
-
req = Net::HTTP.const_get(m.capitalize).new(uri.
|
30
|
+
req = Net::HTTP.const_get(m.capitalize).new(uri.request_uri, headers)
|
31
|
+
req.content_length = rackreq.body.length
|
31
32
|
req.body_stream = rackreq.body
|
32
33
|
else
|
33
|
-
raise "method not supported: #{
|
34
|
+
raise "method not supported: #{m}"
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
+
body = ''
|
38
|
+
res = http.request(req) do |res|
|
39
|
+
res.read_body do |segment|
|
40
|
+
body << segment
|
41
|
+
end
|
42
|
+
end
|
43
|
+
[res.code, Rack::Utils::HeaderHash.new(res.to_hash), [body]]
|
37
44
|
}
|
38
|
-
|
39
|
-
[res.code, Rack::Utils::HeaderHash.new(res.to_hash), [res.body]]
|
40
45
|
end
|
41
46
|
|
42
47
|
private
|
data/rack-reverse-proxy.gemspec
CHANGED
@@ -5,16 +5,15 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-reverse-proxy}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jon Swope"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-20}
|
13
13
|
s.description = %q{A Rack based reverse proxy for basic needs. Useful for testing or in cases where webserver configuration is unavailable.}
|
14
14
|
s.email = %q{jaswope@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README",
|
18
17
|
"README.rdoc"
|
19
18
|
]
|
20
19
|
s.files = [
|
@@ -36,8 +35,8 @@ Gem::Specification.new do |s|
|
|
36
35
|
s.rubygems_version = %q{1.3.6}
|
37
36
|
s.summary = %q{A Simple Reverse Proxy for Rack}
|
38
37
|
s.test_files = [
|
39
|
-
"spec/
|
40
|
-
"spec/
|
38
|
+
"spec/rack/reverse_proxy_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
41
40
|
]
|
42
41
|
|
43
42
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jon Swope
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-20 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -75,7 +75,6 @@ extensions: []
|
|
75
75
|
|
76
76
|
extra_rdoc_files:
|
77
77
|
- LICENSE
|
78
|
-
- README
|
79
78
|
- README.rdoc
|
80
79
|
files:
|
81
80
|
- .document
|
@@ -89,7 +88,6 @@ files:
|
|
89
88
|
- spec/rack/reverse_proxy_spec.rb
|
90
89
|
- spec/spec.opts
|
91
90
|
- spec/spec_helper.rb
|
92
|
-
- README
|
93
91
|
has_rdoc: true
|
94
92
|
homepage: http://github.com/jaswope/rack-reverse-proxy
|
95
93
|
licenses: []
|
@@ -121,5 +119,5 @@ signing_key:
|
|
121
119
|
specification_version: 3
|
122
120
|
summary: A Simple Reverse Proxy for Rack
|
123
121
|
test_files:
|
124
|
-
- spec/spec_helper.rb
|
125
122
|
- spec/rack/reverse_proxy_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
data/README
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
A Reverse Proxy for Rack
|
2
|
-
|
3
|
-
This is a simple reverse proxy for Rack that pretty heavily rips off Rack Forwarder. It is not meant for production systems (although it may work), as the webserver fronting your app is generally much better at this sort of thing.
|
4
|
-
|
5
|
-
Matchers can be a regex or a string. If a regex is used, you can use the subcaptures in your forwarding url by denoting them with a $.
|
6
|
-
|
7
|
-
Right now if more than one matcher matches any given route, it throws an exception for an ambiguous match. This will probably change later. If no match is found, the call is forwarded to your application.
|
8
|
-
|
9
|
-
Below is an example for configuring the middleware:
|
10
|
-
|
11
|
-
require 'lib/rack/reverse_proxy'
|
12
|
-
|
13
|
-
use Rack::ReverseProxy do
|
14
|
-
# Forward the path /test* to http://example.com/test*
|
15
|
-
reverse_proxy '/test', 'http://example.com/'
|
16
|
-
|
17
|
-
# Forward the path /foo/* to http://example.com/bar/*
|
18
|
-
reverse_proxy /^\/foo(\/.*)$/, 'http://example.com/bar$1'
|
19
|
-
end
|
20
|
-
|
21
|
-
app = proc do |env|
|
22
|
-
[ 200, {'Content-Type' => 'text/plain'}, "b" ]
|
23
|
-
end
|
24
|
-
run app
|
25
|
-
|
26
|
-
|