goliath-reverse-proxy 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +22 -24
- data/goliath-reverse-proxy.gemspec +2 -2
- data/lib/goliath/rack/reverse_proxy.rb +16 -10
- data/spec/goliath/reverse_proxy_spec.rb +49 -36
- data/spec/spec_helper.rb +4 -0
- metadata +6 -6
data/Gemfile.lock
CHANGED
@@ -1,63 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
goliath-reverse-proxy (0.
|
5
|
-
em-http-request
|
4
|
+
goliath-reverse-proxy (0.2.0)
|
5
|
+
em-http-request (~> 1.0.3)
|
6
6
|
em-synchrony
|
7
7
|
goliath
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
addressable (2.2
|
12
|
+
addressable (2.3.2)
|
13
13
|
async-rack (0.5.1)
|
14
14
|
rack (~> 1.1)
|
15
15
|
cookiejar (0.3.0)
|
16
16
|
diff-lcs (1.1.3)
|
17
|
-
em-http-request (1.0.
|
17
|
+
em-http-request (1.0.3)
|
18
18
|
addressable (>= 2.2.3)
|
19
19
|
cookiejar
|
20
20
|
em-socksify
|
21
21
|
eventmachine (>= 1.0.0.beta.4)
|
22
22
|
http_parser.rb (>= 0.5.3)
|
23
|
-
em-socksify (0.2.
|
23
|
+
em-socksify (0.2.1)
|
24
24
|
eventmachine (>= 1.0.0.beta.4)
|
25
|
-
em-synchrony (1.0.
|
25
|
+
em-synchrony (1.0.2)
|
26
26
|
eventmachine (>= 1.0.0.beta.1)
|
27
|
-
|
28
|
-
|
27
|
+
em-websocket (0.3.8)
|
28
|
+
addressable (>= 2.1.1)
|
29
|
+
eventmachine (>= 0.12.9)
|
30
|
+
eventmachine (1.0.0.rc.4)
|
31
|
+
goliath (1.0.0)
|
29
32
|
async-rack
|
30
33
|
em-synchrony (>= 1.0.0)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
em-websocket
|
35
|
+
eventmachine (>= 1.0.0.beta.4)
|
36
|
+
http_parser.rb (= 0.5.3)
|
34
37
|
log4r
|
35
38
|
multi_json
|
36
39
|
rack (>= 1.2.2)
|
37
40
|
rack-contrib
|
38
41
|
rack-respond_to
|
39
42
|
http_parser.rb (0.5.3)
|
40
|
-
http_router (0.9.7)
|
41
|
-
rack (>= 1.0.0)
|
42
|
-
url_mount (~> 0.2.1)
|
43
43
|
log4r (1.1.10)
|
44
|
-
multi_json (1.3.
|
44
|
+
multi_json (1.3.6)
|
45
45
|
rack (1.4.1)
|
46
46
|
rack-accept-media-types (0.9)
|
47
47
|
rack-contrib (1.1.0)
|
48
48
|
rack (>= 0.9.1)
|
49
49
|
rack-respond_to (0.9.8)
|
50
50
|
rack-accept-media-types (>= 0.6)
|
51
|
-
rspec (2.
|
52
|
-
rspec-core (~> 2.
|
53
|
-
rspec-expectations (~> 2.
|
54
|
-
rspec-mocks (~> 2.
|
55
|
-
rspec-core (2.
|
56
|
-
rspec-expectations (2.
|
51
|
+
rspec (2.11.0)
|
52
|
+
rspec-core (~> 2.11.0)
|
53
|
+
rspec-expectations (~> 2.11.0)
|
54
|
+
rspec-mocks (~> 2.11.0)
|
55
|
+
rspec-core (2.11.1)
|
56
|
+
rspec-expectations (2.11.2)
|
57
57
|
diff-lcs (~> 1.1.3)
|
58
|
-
rspec-mocks (2.
|
59
|
-
url_mount (0.2.1)
|
60
|
-
rack
|
58
|
+
rspec-mocks (2.11.2)
|
61
59
|
|
62
60
|
PLATFORMS
|
63
61
|
ruby
|
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'goliath-reverse-proxy'
|
5
|
-
gem.version = '0.
|
5
|
+
gem.version = '0.2.0'
|
6
6
|
gem.authors = ["Daniel Farrell"]
|
7
7
|
gem.email = 'danielfarrell76@gmail.com'
|
8
8
|
gem.homepage = 'https://github.com/danielfarrell/goliath-reverse-proxy'
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
|
13
13
|
gem.add_dependency "goliath"
|
14
14
|
gem.add_dependency "em-synchrony"
|
15
|
-
gem.add_dependency "em-http-request"
|
15
|
+
gem.add_dependency "em-http-request", "~> 1.0.3"
|
16
16
|
|
17
17
|
gem.add_development_dependency "rspec", "~> 2.10"
|
18
18
|
|
@@ -7,26 +7,32 @@ module Goliath
|
|
7
7
|
|
8
8
|
def initialize(app, options)
|
9
9
|
@app = app
|
10
|
-
@
|
10
|
+
@connection = EM::HttpRequest.new(options[:base_url])
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def call(env)
|
14
|
+
connection = @connection.dup
|
15
|
+
super(env, connection)
|
16
|
+
end
|
17
|
+
|
18
|
+
def post_process(env, status, headers, body, connection)
|
14
19
|
method = env['REQUEST_METHOD'].downcase.to_sym
|
15
20
|
|
16
|
-
|
21
|
+
options = {:head => request_headers(env, headers), :path => env['REQUEST_URI']}
|
22
|
+
options[:body] = env['params'] if [:put, :post, :patch].include? method
|
17
23
|
|
24
|
+
http = connection.send(method, options)
|
25
|
+
|
26
|
+
[http.response_header.status, http.response_header.raw, [http.response]]
|
27
|
+
end
|
28
|
+
|
29
|
+
def request_headers(env, headers)
|
18
30
|
env.each do |key, value|
|
19
31
|
headers[$1] = value if key =~ /HTTP_(.*)/
|
20
32
|
end
|
21
33
|
headers['X-Forwarded-Host'] = env['HTTP_HOST']
|
22
34
|
headers['X-Forwarded-User'] = env['REMOTE_USER'] if env['REMOTE_USER']
|
23
|
-
|
24
|
-
params = {:head => headers}
|
25
|
-
params[:body] = env['params'] if [:put, :post, :patch].include? method
|
26
|
-
|
27
|
-
http = EM::HttpRequest.new(url).send(method, params)
|
28
|
-
|
29
|
-
[http.response_header.status, http.response_header, [http.response]]
|
35
|
+
headers
|
30
36
|
end
|
31
37
|
|
32
38
|
end
|
@@ -2,6 +2,11 @@ require 'spec_helper'
|
|
2
2
|
require 'goliath/rack/reverse_proxy'
|
3
3
|
|
4
4
|
describe Goliath::Rack::ReverseProxy do
|
5
|
+
|
6
|
+
def failed
|
7
|
+
EM.stop
|
8
|
+
end
|
9
|
+
|
5
10
|
it 'should load without errors' do
|
6
11
|
lambda { Goliath::Rack::ReverseProxy.new('app', {:base_url => 'http://localhost'}) }.should_not raise_error
|
7
12
|
end
|
@@ -11,58 +16,66 @@ describe Goliath::Rack::ReverseProxy do
|
|
11
16
|
@app = double('app').as_null_object
|
12
17
|
@app.should_receive(:call).and_return(initial_response)
|
13
18
|
@env = Goliath::Env.new
|
19
|
+
@stub_connection = EventMachine::HttpConnection.new
|
20
|
+
@stub_connection.stub(:dup => @stub_connection)
|
21
|
+
EM::HttpRequest.should_receive(:new).with('http://localhost').and_return(@stub_connection)
|
14
22
|
@proxy = Goliath::Rack::ReverseProxy.new(@app, {:base_url => 'http://localhost'})
|
15
23
|
end
|
16
24
|
|
17
25
|
it 'should create url to proxy to' do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
26
|
+
EM.synchrony do
|
27
|
+
@env['REQUEST_METHOD'] = 'GET'
|
28
|
+
@env['REQUEST_URI'] = '/a/test/file.html'
|
29
|
+
@stub_connection.should_receive(:get).and_return(response_object)
|
30
|
+
@proxy.call(@env)
|
31
|
+
EM.stop
|
32
|
+
end
|
24
33
|
end
|
25
34
|
|
26
35
|
it 'should build the needed headers' do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
EM.synchrony do
|
37
|
+
@env['REQUEST_METHOD'] = 'GET'
|
38
|
+
@env['REQUEST_URI'] = '/'
|
39
|
+
@env['SERVER_NAME'] = 'test.com'
|
40
|
+
@env['HTTP_HOST'] = 'testing.com'
|
41
|
+
@env['REMOTE_USER'] = 'bob'
|
42
|
+
headers = {"HOST"=>"testing.com", "X-Forwarded-Host"=>"testing.com", "X-Forwarded-User"=>"bob"}
|
43
|
+
@stub_connection.should_receive(:get).with(:head => headers, :path => @env['REQUEST_URI']).and_return(response_object)
|
44
|
+
@proxy.call(@env)
|
45
|
+
EM.stop
|
46
|
+
end
|
37
47
|
end
|
38
48
|
|
39
49
|
it 'should do a delete if a get was sent' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
EM.synchrony do
|
51
|
+
@env['REQUEST_METHOD'] = 'DELETE'
|
52
|
+
@env['REQUEST_URI'] = '/some/item/23'
|
53
|
+
@stub_connection.should_receive(:delete).and_return(response_object)
|
54
|
+
@proxy.call(@env)
|
55
|
+
EM.stop
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
it 'should do a post with body if a post was sent' do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
60
|
+
EM.synchrony do
|
61
|
+
@env['REQUEST_METHOD'] = 'POST'
|
62
|
+
@env['REQUEST_URI'] = '/some/item'
|
63
|
+
@stub_connection.should_receive(:post).and_return(response_object)
|
64
|
+
@proxy.call(@env)
|
65
|
+
EM.stop
|
66
|
+
end
|
55
67
|
end
|
56
68
|
|
57
69
|
it 'should return the response from the proxied request' do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
70
|
+
EM.synchrony do
|
71
|
+
@env['REQUEST_METHOD'] = 'GET'
|
72
|
+
@env['REQUEST_URI'] = '/a/test/file.html'
|
73
|
+
results = response_object(401, {}, ['testing'])
|
74
|
+
@stub_connection.should_receive(:get).and_return(results)
|
75
|
+
response = @proxy.call(@env)
|
76
|
+
response.should == [401, {}, [["testing"]]]
|
77
|
+
EM.stop
|
78
|
+
end
|
66
79
|
end
|
67
80
|
|
68
81
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goliath-reverse-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: goliath
|
@@ -48,17 +48,17 @@ dependencies:
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 1.0.3
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.0.3
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rspec
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|