rack-reverse-proxy 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +5 -0
- data/.gitignore +16 -0
- data/.rspec +1 -0
- data/.rubocop.yml +21 -0
- data/.travis.yml +19 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +20 -0
- data/README.md +30 -4
- data/Rakefile +10 -0
- data/lib/rack/reverse_proxy.rb +3 -128
- data/lib/rack_reverse_proxy.rb +8 -0
- data/lib/rack_reverse_proxy/errors.rb +36 -0
- data/lib/rack_reverse_proxy/middleware.rb +40 -0
- data/lib/rack_reverse_proxy/response_builder.rb +60 -0
- data/lib/rack_reverse_proxy/roundtrip.rb +263 -0
- data/lib/rack_reverse_proxy/rule.rb +182 -0
- data/lib/rack_reverse_proxy/version.rb +4 -0
- data/rack-reverse-proxy.gemspec +42 -0
- data/script/rubocop +5 -0
- data/spec/rack/reverse_proxy_spec.rb +586 -0
- data/spec/rack_reverse_proxy/response_builder_spec.rb +37 -0
- data/spec/spec_helper.rb +106 -0
- data/spec/support/http_streaming_response_patch.rb +32 -0
- metadata +58 -42
- data/lib/rack/exception.rb +0 -31
- data/lib/rack/reverse_proxy/http_streaming_response.rb +0 -7
- data/lib/rack/reverse_proxy_matcher.rb +0 -53
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module RackReverseProxy
|
4
|
+
RSpec.describe ResponseBuilder do
|
5
|
+
let(:options) { {} }
|
6
|
+
let(:uri_opt) { { :uri => "http://example.org/hello/world" } }
|
7
|
+
let(:request) { double("Request") }
|
8
|
+
|
9
|
+
subject(:response) do
|
10
|
+
ResponseBuilder.new(
|
11
|
+
request,
|
12
|
+
URI(uri_opt[:uri]),
|
13
|
+
options
|
14
|
+
).fetch
|
15
|
+
end
|
16
|
+
|
17
|
+
it "is a Rack::HttpStreamingResponse" do
|
18
|
+
expect(response).to be_a(Rack::HttpStreamingResponse)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets up read timeout" do
|
22
|
+
options[:timeout] = 42
|
23
|
+
expect(response.read_timeout).to eq(42)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets up ssl when needed" do
|
27
|
+
uri_opt[:uri] = "https://example.org/hello/world"
|
28
|
+
expect(response.use_ssl).to eq(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "it is possible to change ssl verify mode" do
|
32
|
+
mode = OpenSSL::SSL::VERIFY_NONE
|
33
|
+
options[:verify_mode] = mode
|
34
|
+
expect(response.verify_mode).to eq(mode)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Code coverage
|
2
|
+
require "simplecov"
|
3
|
+
SimpleCov.start
|
4
|
+
|
5
|
+
require "rack/reverse_proxy"
|
6
|
+
require "rack/test"
|
7
|
+
require "webmock/rspec"
|
8
|
+
|
9
|
+
# Patch HttpStreamingResponse to make rack-proxy compatible with webmocks
|
10
|
+
require "support/http_streaming_response_patch"
|
11
|
+
|
12
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
13
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
14
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
15
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
16
|
+
# files.
|
17
|
+
#
|
18
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
19
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
20
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
21
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
22
|
+
# a separate helper file that requires the additional dependencies and performs
|
23
|
+
# the additional setup, and require it from the spec files that actually need
|
24
|
+
# it.
|
25
|
+
#
|
26
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
27
|
+
# users commonly want.
|
28
|
+
#
|
29
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
30
|
+
RSpec.configure do |config|
|
31
|
+
# rspec-expectations config goes here. You can use an alternate
|
32
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
33
|
+
# assertions if you prefer.
|
34
|
+
config.expect_with :rspec do |expectations|
|
35
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
36
|
+
# and `failure_message` of custom matchers include text for helper methods
|
37
|
+
# defined using `chain`, e.g.:
|
38
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
39
|
+
# # => "be bigger than 2 and smaller than 4"
|
40
|
+
# ...rather than:
|
41
|
+
# # => "be bigger than 2"
|
42
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
43
|
+
end
|
44
|
+
|
45
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
46
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
47
|
+
config.mock_with :rspec do |mocks|
|
48
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
49
|
+
# a real object. This is generally recommended, and will default to
|
50
|
+
# `true` in RSpec 4.
|
51
|
+
mocks.verify_partial_doubles = true
|
52
|
+
end
|
53
|
+
|
54
|
+
# These two settings work together to allow you to limit a spec run
|
55
|
+
# to individual examples or groups you care about by tagging them with
|
56
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
57
|
+
# get run.
|
58
|
+
config.filter_run :focus
|
59
|
+
config.run_all_when_everything_filtered = true
|
60
|
+
|
61
|
+
# Allows RSpec to persist some state between runs in order to support
|
62
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
63
|
+
# you configure your source control system to ignore this file.
|
64
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
65
|
+
|
66
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
67
|
+
# recommended. For more details, see:
|
68
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
69
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
70
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
71
|
+
config.disable_monkey_patching!
|
72
|
+
|
73
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
74
|
+
# be too noisy due to issues in dependencies.
|
75
|
+
config.warnings = true
|
76
|
+
|
77
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
78
|
+
# file, and it's useful to allow more verbose output when running an
|
79
|
+
# individual spec file.
|
80
|
+
if config.files_to_run.one?
|
81
|
+
# Use the documentation formatter for detailed output,
|
82
|
+
# unless a formatter has already been configured
|
83
|
+
# (e.g. via a command-line flag).
|
84
|
+
config.default_formatter = "doc"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Print the 10 slowest examples and example groups at the
|
88
|
+
# end of the spec run, to help surface which specs are running
|
89
|
+
# particularly slow.
|
90
|
+
config.profile_examples = 10
|
91
|
+
|
92
|
+
# Run specs in random order to surface order dependencies. If you find an
|
93
|
+
# order dependency and want to debug it, you can fix the order by providing
|
94
|
+
# the seed, which is printed after each run.
|
95
|
+
# --seed 1234
|
96
|
+
config.order = :random
|
97
|
+
|
98
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
99
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
100
|
+
# test failures related to randomization by passing the same `--seed` value
|
101
|
+
# as the one that triggered the failure.
|
102
|
+
Kernel.srand config.seed
|
103
|
+
|
104
|
+
# User-defined configuration
|
105
|
+
WebMock.disable_net_connect!
|
106
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Rack
|
2
|
+
##
|
3
|
+
# Patch HttpStreamingResponse
|
4
|
+
# in order to support webmocks and still use rack-proxy
|
5
|
+
#
|
6
|
+
# Inspired by @ehlertij commits on sportngin/rack-proxy:
|
7
|
+
# 616574e452fa731f5427d2ff2aff6823fcf28bde
|
8
|
+
# d8c377f7485997b229ced23c33cfef87d3fb8693
|
9
|
+
# 75b446a26ceb519ddc28f38b33309e9a2799074c
|
10
|
+
#
|
11
|
+
class HttpStreamingResponse
|
12
|
+
def each(&block)
|
13
|
+
response.read_body(&block)
|
14
|
+
ensure
|
15
|
+
session.end_request_hacked unless mocking?
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def response
|
21
|
+
if mocking?
|
22
|
+
@response ||= session.request(@request)
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def mocking?
|
29
|
+
defined?(WebMock) || defined?(FakeWeb)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
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.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Swope
|
@@ -11,80 +11,73 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
18
|
-
requirement: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - "~>"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '10.3'
|
23
|
-
type: :development
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '10.3'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: guard-rspec
|
17
|
+
name: rack
|
32
18
|
requirement: !ruby/object:Gem::Requirement
|
33
19
|
requirements:
|
34
20
|
- - ">="
|
35
21
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
type: :
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
38
24
|
prerelease: false
|
39
25
|
version_requirements: !ruby/object:Gem::Requirement
|
40
26
|
requirements:
|
41
27
|
- - ">="
|
42
28
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
29
|
+
version: 1.0.0
|
44
30
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
31
|
+
name: rack-proxy
|
46
32
|
requirement: !ruby/object:Gem::Requirement
|
47
33
|
requirements:
|
34
|
+
- - "~>"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0.5'
|
48
37
|
- - ">="
|
49
38
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
51
|
-
type: :
|
39
|
+
version: 0.5.14
|
40
|
+
type: :runtime
|
52
41
|
prerelease: false
|
53
42
|
version_requirements: !ruby/object:Gem::Requirement
|
54
43
|
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.5'
|
55
47
|
- - ">="
|
56
48
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
49
|
+
version: 0.5.14
|
58
50
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
51
|
+
name: bundler
|
60
52
|
requirement: !ruby/object:Gem::Requirement
|
61
53
|
requirements:
|
62
|
-
- - "
|
54
|
+
- - "~>"
|
63
55
|
- !ruby/object:Gem::Version
|
64
|
-
version: 1.
|
65
|
-
type: :
|
56
|
+
version: '1.7'
|
57
|
+
type: :development
|
66
58
|
prerelease: false
|
67
59
|
version_requirements: !ruby/object:Gem::Requirement
|
68
60
|
requirements:
|
69
|
-
- - "
|
61
|
+
- - "~>"
|
70
62
|
- !ruby/object:Gem::Version
|
71
|
-
version: 1.
|
63
|
+
version: '1.7'
|
72
64
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
65
|
+
name: rake
|
74
66
|
requirement: !ruby/object:Gem::Requirement
|
75
67
|
requirements:
|
76
68
|
- - "~>"
|
77
69
|
- !ruby/object:Gem::Version
|
78
|
-
version: '
|
79
|
-
type: :
|
70
|
+
version: '10.3'
|
71
|
+
type: :development
|
80
72
|
prerelease: false
|
81
73
|
version_requirements: !ruby/object:Gem::Requirement
|
82
74
|
requirements:
|
83
75
|
- - "~>"
|
84
76
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
86
|
-
description:
|
87
|
-
|
77
|
+
version: '10.3'
|
78
|
+
description: |
|
79
|
+
A Rack based reverse proxy for basic needs.
|
80
|
+
Useful for testing or in cases where webserver configuration is unavailable.
|
88
81
|
email:
|
89
82
|
- jaswope@gmail.com
|
90
83
|
- ehlertij@gmail.com
|
@@ -94,14 +87,33 @@ executables: []
|
|
94
87
|
extensions: []
|
95
88
|
extra_rdoc_files: []
|
96
89
|
files:
|
90
|
+
- ".document"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CHANGELOG.md
|
96
|
+
- Gemfile
|
97
97
|
- LICENSE
|
98
98
|
- README.md
|
99
|
-
-
|
99
|
+
- Rakefile
|
100
100
|
- lib/rack/reverse_proxy.rb
|
101
|
-
- lib/
|
102
|
-
- lib/
|
103
|
-
|
104
|
-
|
101
|
+
- lib/rack_reverse_proxy.rb
|
102
|
+
- lib/rack_reverse_proxy/errors.rb
|
103
|
+
- lib/rack_reverse_proxy/middleware.rb
|
104
|
+
- lib/rack_reverse_proxy/response_builder.rb
|
105
|
+
- lib/rack_reverse_proxy/roundtrip.rb
|
106
|
+
- lib/rack_reverse_proxy/rule.rb
|
107
|
+
- lib/rack_reverse_proxy/version.rb
|
108
|
+
- rack-reverse-proxy.gemspec
|
109
|
+
- script/rubocop
|
110
|
+
- spec/rack/reverse_proxy_spec.rb
|
111
|
+
- spec/rack_reverse_proxy/response_builder_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/support/http_streaming_response_patch.rb
|
114
|
+
homepage: https://github.com/waterlink/rack-reverse-proxy
|
115
|
+
licenses:
|
116
|
+
- MIT
|
105
117
|
metadata: {}
|
106
118
|
post_install_message:
|
107
119
|
rdoc_options: []
|
@@ -123,4 +135,8 @@ rubygems_version: 2.4.6
|
|
123
135
|
signing_key:
|
124
136
|
specification_version: 4
|
125
137
|
summary: A Simple Reverse Proxy for Rack
|
126
|
-
test_files:
|
138
|
+
test_files:
|
139
|
+
- spec/rack/reverse_proxy_spec.rb
|
140
|
+
- spec/rack_reverse_proxy/response_builder_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/support/http_streaming_response_patch.rb
|
data/lib/rack/exception.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Rack
|
2
|
-
class GenericProxyURI < Exception
|
3
|
-
attr_reader :url
|
4
|
-
|
5
|
-
def intialize(url)
|
6
|
-
@url = url
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_s
|
10
|
-
%Q(Your URL "#{@url}" is too generic. Did you mean "http://#{@url}"?)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class AmbiguousProxyMatch < Exception
|
15
|
-
attr_reader :path, :matches
|
16
|
-
def initialize(path, matches)
|
17
|
-
@path = path
|
18
|
-
@matches = matches
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_s
|
22
|
-
%Q(Path "#{path}" matched multiple endpoints: #{formatted_matches})
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def formatted_matches
|
28
|
-
matches.map {|matcher| matcher.to_s}.join(', ')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Rack
|
2
|
-
class ReverseProxyMatcher
|
3
|
-
def initialize(matcher, url=nil, options={})
|
4
|
-
@default_url=url
|
5
|
-
@url=url
|
6
|
-
@options=options
|
7
|
-
|
8
|
-
if matcher.kind_of?(String)
|
9
|
-
@matcher = /^#{matcher.to_s}/
|
10
|
-
elsif matcher.respond_to?(:match)
|
11
|
-
@matcher = matcher
|
12
|
-
else
|
13
|
-
raise "Invalid Matcher for reverse_proxy"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :matcher,:url, :default_url,:options
|
18
|
-
|
19
|
-
def match?(path, *args)
|
20
|
-
match_path(path, *args) ? true : false
|
21
|
-
end
|
22
|
-
|
23
|
-
def get_uri(path,env)
|
24
|
-
return nil if url.nil?
|
25
|
-
_url=(url.respond_to?(:call) ? url.call(env) : url.clone)
|
26
|
-
if _url =~/\$\d/
|
27
|
-
match_path(path).to_a.each_with_index { |m, i| _url.gsub!("$#{i.to_s}", m) }
|
28
|
-
URI(_url)
|
29
|
-
else
|
30
|
-
default_url.nil? ? URI.parse(_url) : URI.join(_url, path)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
%Q("#{matcher.to_s}" => "#{url}")
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
def match_path(path, *args)
|
40
|
-
headers = args[0]
|
41
|
-
rackreq = args[1]
|
42
|
-
arity = matcher.method(:match).arity
|
43
|
-
if arity == -1
|
44
|
-
match = matcher.match(path)
|
45
|
-
else
|
46
|
-
params = [path, (@options[:accept_headers] ? headers : nil), rackreq]
|
47
|
-
match = matcher.match(*params[0..(arity - 1)])
|
48
|
-
end
|
49
|
-
@url = match.url(path) if match && default_url.nil?
|
50
|
-
match
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|