rack-reverse-proxy 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/rack_reverse_proxy/middleware.rb +2 -1
- data/lib/rack_reverse_proxy/roundtrip.rb +9 -3
- data/lib/rack_reverse_proxy/version.rb +1 -1
- data/spec/rack/reverse_proxy_spec.rb +66 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5006b032a51816d16876f3a92b9a1e0435483832
|
4
|
+
data.tar.gz: 8c5b31b2cff31606543f2d216bc2937178926b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20c79748659c8c1e0e52294322b7470a7f31cd4ac6c32e83f9d035044badb02f2c9ea5db1b97839c12e629643e26b6ecabced99f7ad6afdc80eccee015e87b38
|
7
|
+
data.tar.gz: 5990b64a3e455ecfc80f67d5c6059fc48fc1fb0eb94c266653d511459628f118e3158c40612dd7dfe0e2da887916cff8ab4a1ce07e8159d907de7fd35e03c033
|
data/README.md
CHANGED
@@ -53,6 +53,8 @@ run app
|
|
53
53
|
* `:timeout` seconds to timout the requests
|
54
54
|
* `:force_ssl` redirects to ssl version, if not already using it (requires `:replace_response_host`). Default: false.
|
55
55
|
* `:verify_mode` the `OpenSSL::SSL` verify mode passed to Net::HTTP. Default: `OpenSSL::SSL::VERIFY_PEER`.
|
56
|
+
* `:x_forwarded_headers` sets up proper `X-Forwarded-*` headers. Default: true.
|
57
|
+
* `:preserve_encoding` Set to true to pass Accept-Encoding header to proxy server. Default: false.
|
56
58
|
|
57
59
|
### Sample usage in a Ruby on Rails app
|
58
60
|
|
@@ -84,13 +84,18 @@ module RackReverseProxy
|
|
84
84
|
target_request_headers["HOST"] = host_header
|
85
85
|
end
|
86
86
|
|
87
|
+
def preserve_encoding
|
88
|
+
return if options[:preserve_encoding]
|
89
|
+
target_request_headers.delete("Accept-Encoding")
|
90
|
+
end
|
91
|
+
|
87
92
|
def host_header
|
88
93
|
return uri.host if uri.port == uri.default_port
|
89
94
|
"#{uri.host}:#{uri.port}"
|
90
95
|
end
|
91
96
|
|
92
|
-
def
|
93
|
-
return unless options[:
|
97
|
+
def set_forwarded_headers
|
98
|
+
return unless options[:x_forwarded_headers]
|
94
99
|
target_request_headers["X-Forwarded-Host"] = source_request.host
|
95
100
|
target_request_headers["X-Forwarded-Port"] = source_request.port.to_s
|
96
101
|
end
|
@@ -178,7 +183,8 @@ module RackReverseProxy
|
|
178
183
|
|
179
184
|
def setup_request
|
180
185
|
preserve_host
|
181
|
-
|
186
|
+
preserve_encoding
|
187
|
+
set_forwarded_headers
|
182
188
|
initialize_http_header
|
183
189
|
set_basic_auth
|
184
190
|
setup_body
|
@@ -63,6 +63,15 @@ RSpec.describe Rack::ReverseProxy do
|
|
63
63
|
expect(last_response.body).to eq("Proxied App2")
|
64
64
|
end
|
65
65
|
|
66
|
+
it "returns headers from proxied app as strings" do
|
67
|
+
stub_request(:get, "http://example.com/test").to_return(
|
68
|
+
:body => "Proxied App",
|
69
|
+
:headers => { "Proxied-Header" => "TestValue" }
|
70
|
+
)
|
71
|
+
get "/test"
|
72
|
+
expect(last_response.headers["Proxied-Header"]).to eq("TestValue")
|
73
|
+
end
|
74
|
+
|
66
75
|
it "sets the Host header w/o default port" do
|
67
76
|
stub_request(:any, "example.com/test/stuff")
|
68
77
|
get "/test/stuff"
|
@@ -83,6 +92,16 @@ RSpec.describe Rack::ReverseProxy do
|
|
83
92
|
).to have_been_made
|
84
93
|
end
|
85
94
|
|
95
|
+
it "sets the X-Forwarded-Port header to the proxying port by default" do
|
96
|
+
stub_request(:any, "example.com/test/stuff")
|
97
|
+
get "/test/stuff"
|
98
|
+
expect(
|
99
|
+
a_request(:get, "http://example.com/test/stuff").with(
|
100
|
+
:headers => { "X-Forwarded-Port" => "80" }
|
101
|
+
)
|
102
|
+
).to have_been_made
|
103
|
+
end
|
104
|
+
|
86
105
|
it "does not produce headers with a Status key" do
|
87
106
|
stub_request(:get, "http://example.com/2test").to_return(
|
88
107
|
:status => 301, :headers => { :status => "301 Moved Permanently" }
|
@@ -128,6 +147,20 @@ RSpec.describe Rack::ReverseProxy do
|
|
128
147
|
expect(last_response.headers["Content-Length"]).to eq(body.length.to_s)
|
129
148
|
end
|
130
149
|
|
150
|
+
it "does not include Accept-Encoding header" do
|
151
|
+
stub_request(:any, "http://example.com/test")
|
152
|
+
|
153
|
+
get "/test", {}, "HTTP_ACCEPT_ENCODING" => "gzip, deflate"
|
154
|
+
|
155
|
+
expect(
|
156
|
+
a_request(:get, "http://example.com/test").with(
|
157
|
+
:headers => { "Accept-Encoding" => "gzip, deflate" }
|
158
|
+
)
|
159
|
+
).not_to have_been_made
|
160
|
+
|
161
|
+
expect(a_request(:get, "http://example.com/test")).to have_been_made
|
162
|
+
end
|
163
|
+
|
131
164
|
describe "with non-default port" do
|
132
165
|
def app
|
133
166
|
Rack::ReverseProxy.new(dummy_app) do
|
@@ -167,10 +200,30 @@ RSpec.describe Rack::ReverseProxy do
|
|
167
200
|
end
|
168
201
|
end
|
169
202
|
|
170
|
-
describe "with
|
203
|
+
describe "with preserve encoding turned on" do
|
204
|
+
def app
|
205
|
+
Rack::ReverseProxy.new(dummy_app) do
|
206
|
+
reverse_proxy "/test", "http://example.com/", :preserve_encoding => true
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
it "sets the Accept-Encoding header" do
|
211
|
+
stub_request(:any, "http://example.com/test")
|
212
|
+
|
213
|
+
get "/test", {}, "HTTP_ACCEPT_ENCODING" => "gzip, deflate"
|
214
|
+
|
215
|
+
expect(
|
216
|
+
a_request(:get, "http://example.com/test").with(
|
217
|
+
:headers => { "Accept-Encoding" => "gzip, deflate" }
|
218
|
+
)
|
219
|
+
).to have_been_made
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "with x_forwarded_headers turned off" do
|
171
224
|
def app
|
172
225
|
Rack::ReverseProxy.new(dummy_app) do
|
173
|
-
reverse_proxy_options :
|
226
|
+
reverse_proxy_options :x_forwarded_headers => false
|
174
227
|
reverse_proxy "/test", "http://example.com/"
|
175
228
|
end
|
176
229
|
end
|
@@ -185,6 +238,17 @@ RSpec.describe Rack::ReverseProxy do
|
|
185
238
|
).not_to have_been_made
|
186
239
|
expect(a_request(:get, "http://example.com/test/stuff")).to have_been_made
|
187
240
|
end
|
241
|
+
|
242
|
+
it "does not set the X-Forwarded-Port header to the proxying port" do
|
243
|
+
stub_request(:any, "example.com/test/stuff")
|
244
|
+
get "/test/stuff"
|
245
|
+
expect(
|
246
|
+
a_request(:get, "http://example.com/test/stuff").with(
|
247
|
+
:headers => { "X-Forwarded-Port" => "80" }
|
248
|
+
)
|
249
|
+
).not_to have_been_made
|
250
|
+
expect(a_request(:get, "http://example.com/test/stuff")).to have_been_made
|
251
|
+
end
|
188
252
|
end
|
189
253
|
|
190
254
|
describe "with timeout configuration" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-reverse-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Swope
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-02
|
14
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rack
|