rack-reverse-proxy 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -8
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/rack_reverse_proxy/errors.rb +2 -2
- data/lib/rack_reverse_proxy/roundtrip.rb +7 -2
- data/lib/rack_reverse_proxy/rule.rb +24 -0
- data/lib/rack_reverse_proxy/version.rb +1 -1
- data/rack-reverse-proxy.gemspec +3 -1
- data/spec/rack/reverse_proxy_spec.rb +69 -4
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 585ae7eb632c419d011c716865928e286d795fcc
|
4
|
+
data.tar.gz: 90b7af6bfcabf097166b5e5e24f4fb3346baa4cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af3323dcc567ef1c2f1bb177e926d3f65efe8ed3dd0218d3765a5495f30d45aa3527bd744beca11a103e8612b6d71976e8712414dea80abac85e7875d6f6d476
|
7
|
+
data.tar.gz: d9978acd0a9122f0a43b313a41ea25333e2ec387c46ca7cdb1835bdeb1ebb9fa0db124a28103127bc91eac8f3fa1e6a2884be9cd08ee354cf5bcb923f48edc86
|
data/.travis.yml
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
-
|
5
|
-
- 2.
|
6
|
-
-
|
7
|
-
- 2.2
|
8
|
-
- jruby-18mode
|
9
|
-
- jruby-19mode
|
3
|
+
- 2.2.5
|
4
|
+
- 2.3.1
|
5
|
+
- 2.4.1
|
6
|
+
- jruby-9.0.5.0
|
10
7
|
- rbx
|
11
8
|
|
12
9
|
before_install:
|
@@ -16,4 +13,7 @@ bundler_args: --without development
|
|
16
13
|
|
17
14
|
script:
|
18
15
|
- bundle exec rspec
|
19
|
-
|
16
|
+
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: rbx
|
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
ruby_version = RUBY_VERSION.to_f
|
6
|
-
rubocop_platform = [:ruby_20, :ruby_21, :ruby_22]
|
6
|
+
rubocop_platform = [:ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24]
|
7
7
|
rubocop_platform = [:ruby_20, :ruby_21] if ruby_version < 2.0
|
8
8
|
|
9
9
|
group :test do
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module RackReverseProxy
|
2
2
|
module Errors
|
3
3
|
# GenericURI indicates that url is too generic
|
4
|
-
class GenericURI <
|
4
|
+
class GenericURI < RuntimeError
|
5
5
|
attr_reader :url
|
6
6
|
|
7
7
|
def intialize(url)
|
@@ -14,7 +14,7 @@ module RackReverseProxy
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# AmbiguousMatch indicates that path matched more than one endpoint
|
17
|
-
class AmbiguousMatch <
|
17
|
+
class AmbiguousMatch < RuntimeError
|
18
18
|
attr_reader :path, :matches
|
19
19
|
|
20
20
|
def initialize(path, matches)
|
@@ -98,6 +98,7 @@ module RackReverseProxy
|
|
98
98
|
return unless options[:x_forwarded_headers]
|
99
99
|
target_request_headers["X-Forwarded-Host"] = source_request.host
|
100
100
|
target_request_headers["X-Forwarded-Port"] = source_request.port.to_s
|
101
|
+
target_request_headers["X-Forwarded-Proto"] = source_request.scheme
|
101
102
|
end
|
102
103
|
|
103
104
|
def initialize_http_header
|
@@ -207,7 +208,11 @@ module RackReverseProxy
|
|
207
208
|
setup_request
|
208
209
|
setup_response_headers
|
209
210
|
|
210
|
-
rack_response
|
211
|
+
transform_response(rack_response)
|
212
|
+
end
|
213
|
+
|
214
|
+
def transform_response(response)
|
215
|
+
rule.transform(path, env, response, uri, headers, source_request)
|
211
216
|
end
|
212
217
|
|
213
218
|
def format_headers(headers)
|
@@ -238,7 +243,7 @@ module RackReverseProxy
|
|
238
243
|
end
|
239
244
|
|
240
245
|
def find_rule
|
241
|
-
return if matches.
|
246
|
+
return if matches.empty?
|
242
247
|
non_ambiguous_match
|
243
248
|
matches.first
|
244
249
|
end
|
@@ -25,6 +25,16 @@ module RackReverseProxy
|
|
25
25
|
).build_uri
|
26
26
|
end
|
27
27
|
|
28
|
+
def transform(path, env, response, request_uri, *args)
|
29
|
+
Candidate.new(
|
30
|
+
self,
|
31
|
+
has_custom_url,
|
32
|
+
path,
|
33
|
+
env,
|
34
|
+
matches(path, *args)
|
35
|
+
).transform(response, request_uri)
|
36
|
+
end
|
37
|
+
|
28
38
|
def to_s
|
29
39
|
%("#{spec}" => "#{url}")
|
30
40
|
end
|
@@ -68,6 +78,10 @@ module RackReverseProxy
|
|
68
78
|
raw_uri
|
69
79
|
end
|
70
80
|
|
81
|
+
def transform(response, request_uri)
|
82
|
+
matches.transform(response, request_uri)
|
83
|
+
end
|
84
|
+
|
71
85
|
private
|
72
86
|
|
73
87
|
attr_reader :rule, :url, :has_custom_url, :path, :env, :matches
|
@@ -138,6 +152,16 @@ module RackReverseProxy
|
|
138
152
|
end
|
139
153
|
end
|
140
154
|
|
155
|
+
def transform(response, request_uri)
|
156
|
+
found.inject(response) do |accumulator, match|
|
157
|
+
if match.respond_to?(:transform)
|
158
|
+
match.transform(accumulator, request_uri)
|
159
|
+
else
|
160
|
+
accumulator
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
141
165
|
private
|
142
166
|
|
143
167
|
attr_reader :spec, :url, :path, :headers, :rackreq, :spec_arity, :has_custom_url
|
data/rack-reverse-proxy.gemspec
CHANGED
@@ -2,6 +2,7 @@ lib = File.expand_path("../lib", __FILE__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require "rack_reverse_proxy/version"
|
4
4
|
|
5
|
+
# rubocop:disable
|
5
6
|
Gem::Specification.new do |spec|
|
6
7
|
spec.name = "rack-reverse-proxy"
|
7
8
|
spec.version = RackReverseProxy::VERSION
|
@@ -35,8 +36,9 @@ eos
|
|
35
36
|
spec.require_paths = ["lib"]
|
36
37
|
|
37
38
|
spec.add_dependency "rack", ">= 1.0.0"
|
38
|
-
spec.add_dependency "rack-proxy", "~> 0.
|
39
|
+
spec.add_dependency "rack-proxy", "~> 0.6", ">= 0.6.1"
|
39
40
|
|
40
41
|
spec.add_development_dependency "bundler", "~> 1.7"
|
41
42
|
spec.add_development_dependency "rake", "~> 10.3"
|
42
43
|
end
|
44
|
+
# rubocop:enable
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "cgi"
|
3
|
+
require "base64"
|
2
4
|
|
3
5
|
RSpec.describe Rack::ReverseProxy do
|
4
6
|
include Rack::Test::Methods
|
@@ -102,6 +104,16 @@ RSpec.describe Rack::ReverseProxy do
|
|
102
104
|
).to have_been_made
|
103
105
|
end
|
104
106
|
|
107
|
+
it "sets the X-Forwarded-Proto header to the proxying scheme by default" do
|
108
|
+
stub_request(:any, "example.com/test/stuff")
|
109
|
+
get "https://example.com/test/stuff"
|
110
|
+
expect(
|
111
|
+
a_request(:get, "example.com/test/stuff").with(
|
112
|
+
:headers => { "X-Forwarded-Proto" => "https" }
|
113
|
+
)
|
114
|
+
).to have_been_made
|
115
|
+
end
|
116
|
+
|
105
117
|
it "does not produce headers with a Status key" do
|
106
118
|
stub_request(:get, "http://example.com/2test").to_return(
|
107
119
|
:status => 301, :headers => { :status => "301 Moved Permanently" }
|
@@ -249,6 +261,17 @@ RSpec.describe Rack::ReverseProxy do
|
|
249
261
|
).not_to have_been_made
|
250
262
|
expect(a_request(:get, "http://example.com/test/stuff")).to have_been_made
|
251
263
|
end
|
264
|
+
|
265
|
+
it "does not set the X-Forwarded-Proto header to the proxying scheme" do
|
266
|
+
stub_request(:any, "example.com/test/stuff")
|
267
|
+
get "https://example.com/test/stuff"
|
268
|
+
expect(
|
269
|
+
a_request(:get, "example.com/test/stuff").with(
|
270
|
+
:headers => { "X-Forwarded-Proto" => "https" }
|
271
|
+
)
|
272
|
+
).not_to have_been_made
|
273
|
+
expect(a_request(:get, "example.com/test/stuff")).to have_been_made
|
274
|
+
end
|
252
275
|
end
|
253
276
|
|
254
277
|
describe "with timeout configuration" do
|
@@ -289,7 +312,9 @@ RSpec.describe Rack::ReverseProxy do
|
|
289
312
|
end
|
290
313
|
|
291
314
|
it "makes request with basic auth" do
|
292
|
-
stub_request(:get, "http://
|
315
|
+
stub_request(:get, "http://example.com/test/stuff").with(
|
316
|
+
:basic_auth => %w(joe shmoe)
|
317
|
+
).to_return(
|
293
318
|
:body => "secured content"
|
294
319
|
)
|
295
320
|
get "/test/stuff"
|
@@ -558,6 +583,46 @@ RSpec.describe Rack::ReverseProxy do
|
|
558
583
|
end
|
559
584
|
end
|
560
585
|
|
586
|
+
describe "with a matching and transforming class" do
|
587
|
+
#:nodoc:
|
588
|
+
class MatcherAndTransformer
|
589
|
+
def self.match(_path)
|
590
|
+
MatcherAndTransformer.new
|
591
|
+
end
|
592
|
+
|
593
|
+
def url(_path)
|
594
|
+
"http://example.org/redirecting"
|
595
|
+
end
|
596
|
+
|
597
|
+
def transform(response, request_uri)
|
598
|
+
status, headers, body = response
|
599
|
+
location = headers["Location"]
|
600
|
+
headers["Location"] = "?url=" + CGI.escape(location) +
|
601
|
+
"&request_uri=" + CGI.escape(request_uri.to_s)
|
602
|
+
[status, headers, body]
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
def app
|
607
|
+
Rack::ReverseProxy.new(dummy_app) do
|
608
|
+
reverse_proxy MatcherAndTransformer
|
609
|
+
end
|
610
|
+
end
|
611
|
+
|
612
|
+
it "transforms the proxied response" do
|
613
|
+
stub_request(:get, "http://example.org/redirecting").to_return(
|
614
|
+
:headers => {
|
615
|
+
"Location" => "http://example.org/target"
|
616
|
+
}
|
617
|
+
)
|
618
|
+
|
619
|
+
get "/"
|
620
|
+
expect(last_response.headers["Location"])
|
621
|
+
.to eq("?url=http%3A%2F%2Fexample.org%2Ftarget" \
|
622
|
+
"&request_uri=http%3A%2F%2Fexample.org%2Fredirecting")
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
561
626
|
describe "with a matching class" do
|
562
627
|
#:nodoc:
|
563
628
|
class RequestMatcher
|
@@ -607,9 +672,9 @@ RSpec.describe Rack::ReverseProxy do
|
|
607
672
|
#:nodoc:
|
608
673
|
class MatcherHeaders
|
609
674
|
def self.match(path, headers)
|
610
|
-
if path.match(%r{^/test}) &&
|
611
|
-
|
612
|
-
|
675
|
+
MatcherHeaders.new if path.match(%r{^/test}) &&
|
676
|
+
headers["ACCEPT"] &&
|
677
|
+
headers["ACCEPT"] == "foo.bar"
|
613
678
|
end
|
614
679
|
|
615
680
|
def url(path)
|
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.12.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:
|
14
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rack
|
@@ -33,20 +33,20 @@ dependencies:
|
|
33
33
|
requirements:
|
34
34
|
- - "~>"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '0.
|
36
|
+
version: '0.6'
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
39
|
+
version: 0.6.1
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0.
|
46
|
+
version: '0.6'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.
|
49
|
+
version: 0.6.1
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: bundler
|
52
52
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.6.10
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: A Simple Reverse Proxy for Rack
|