rack-reverse-proxy-pact 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.github/workflows/test.yml +22 -0
- data/.gitignore +16 -0
- data/.rspec +1 -0
- data/.rubocop.yml +21 -0
- data/.travis.yml +19 -0
- data/CHANGELOG.md +41 -0
- data/Gemfile +20 -0
- data/LICENSE +20 -0
- data/README.md +129 -0
- data/Rakefile +10 -0
- data/lib/rack/reverse_proxy.rb +6 -0
- data/lib/rack_reverse_proxy/errors.rb +36 -0
- data/lib/rack_reverse_proxy/middleware.rb +47 -0
- data/lib/rack_reverse_proxy/response_builder.rb +60 -0
- data/lib/rack_reverse_proxy/roundtrip.rb +286 -0
- data/lib/rack_reverse_proxy/rule.rb +206 -0
- data/lib/rack_reverse_proxy/version.rb +4 -0
- data/lib/rack_reverse_proxy.rb +8 -0
- data/rack-reverse-proxy.gemspec +49 -0
- data/script/rubocop +5 -0
- data/spec/rack/reverse_proxy_spec.rb +768 -0
- data/spec/rack_reverse_proxy/response_builder_spec.rb +37 -0
- data/spec/spec_helper.rb +110 -0
- data/spec/support/http_streaming_response_patch.rb +32 -0
- metadata +168 -0
@@ -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,110 @@
|
|
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
|
+
|
107
|
+
def rack_version_less_than_three
|
108
|
+
Rack.release.split('.').first.to_i < 3
|
109
|
+
end
|
110
|
+
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
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-reverse-proxy-pact
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Swope
|
8
|
+
- Ian Ehlert
|
9
|
+
- Roman Ernst
|
10
|
+
- Oleksii Fedorov
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rack
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
- - "<"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '4.0'
|
26
|
+
type: :runtime
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- - "<"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '4.0'
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rackup
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.0'
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rack-proxy
|
52
|
+
requirement: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.6'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.6.1
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.6'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.6.1
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.7'
|
77
|
+
- - "<"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '3.0'
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '1.7'
|
87
|
+
- - "<"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: rake
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.3'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.3'
|
104
|
+
description: |
|
105
|
+
A Rack based reverse proxy for basic needs.
|
106
|
+
Useful for testing or in cases where webserver configuration is unavailable.
|
107
|
+
email:
|
108
|
+
- jaswope@gmail.com
|
109
|
+
- ehlertij@gmail.com
|
110
|
+
- rernst@farbenmeer.net
|
111
|
+
- waterlink000@gmail.com
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files: []
|
115
|
+
files:
|
116
|
+
- ".document"
|
117
|
+
- ".github/workflows/test.yml"
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- CHANGELOG.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- lib/rack/reverse_proxy.rb
|
128
|
+
- lib/rack_reverse_proxy.rb
|
129
|
+
- lib/rack_reverse_proxy/errors.rb
|
130
|
+
- lib/rack_reverse_proxy/middleware.rb
|
131
|
+
- lib/rack_reverse_proxy/response_builder.rb
|
132
|
+
- lib/rack_reverse_proxy/roundtrip.rb
|
133
|
+
- lib/rack_reverse_proxy/rule.rb
|
134
|
+
- lib/rack_reverse_proxy/version.rb
|
135
|
+
- rack-reverse-proxy.gemspec
|
136
|
+
- script/rubocop
|
137
|
+
- spec/rack/reverse_proxy_spec.rb
|
138
|
+
- spec/rack_reverse_proxy/response_builder_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/support/http_streaming_response_patch.rb
|
141
|
+
homepage: https://github.com/waterlink/rack-reverse-proxy
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubygems_version: 3.5.23
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: A Simple Reverse Proxy for Rack
|
164
|
+
test_files:
|
165
|
+
- spec/rack/reverse_proxy_spec.rb
|
166
|
+
- spec/rack_reverse_proxy/response_builder_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/support/http_streaming_response_patch.rb
|