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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff26702f215fd146c4a043bc583a058f7102001b
4
- data.tar.gz: c451349b33d1715e57ce4da1652bba7f4a7b9192
3
+ metadata.gz: 5006b032a51816d16876f3a92b9a1e0435483832
4
+ data.tar.gz: 8c5b31b2cff31606543f2d216bc2937178926b1f
5
5
  SHA512:
6
- metadata.gz: 0916fd37a7f4f5c4a63d3a51d01ad07f60c6a687fa45db392f1816dcb63dd82608b466f6451b7a169f7c66b252dceb697e0e0bdd8c86cad4a7fa145ce9895a4a
7
- data.tar.gz: fb4a7b6158ffb9ae52c6689d0e71f95fdcbb1b0a1e131e7d3e5c7c2677096121af205b04be922d1521a075a35ae5ab9ba8ae9875ffab3aece726763a3b27a50c
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
 
@@ -13,7 +13,8 @@ module RackReverseProxy
13
13
  @rules = []
14
14
  @global_options = {
15
15
  :preserve_host => true,
16
- :x_forwarded_host => true,
16
+ :preserve_encoding => false,
17
+ :x_forwarded_headers => true,
17
18
  :matching => :all,
18
19
  :replace_response_host => false
19
20
  }
@@ -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 set_forwarded_host
93
- return unless options[:x_forwarded_host]
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
- set_forwarded_host
186
+ preserve_encoding
187
+ set_forwarded_headers
182
188
  initialize_http_header
183
189
  set_basic_auth
184
190
  setup_body
@@ -1,4 +1,4 @@
1
1
  #:nodoc:
2
2
  module RackReverseProxy
3
- VERSION = "0.10.0".freeze
3
+ VERSION = "0.11.0".freeze
4
4
  end
@@ -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 x_forwarded_host turned off" do
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 :x_forwarded_host => false
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.10.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-16 00:00:00.000000000 Z
14
+ date: 2016-03-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rack