ultra-pure-gem 0.0.1
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/ultra-pure-gem.gemspec +12 -0
- data/webmock-3.26.2/CHANGELOG.md +2148 -0
- data/webmock-3.26.2/LICENSE +20 -0
- data/webmock-3.26.2/README.md +1229 -0
- data/webmock-3.26.2/lib/webmock/api.rb +111 -0
- data/webmock-3.26.2/lib/webmock/assertion_failure.rb +13 -0
- data/webmock-3.26.2/lib/webmock/callback_registry.rb +37 -0
- data/webmock-3.26.2/lib/webmock/config.rb +20 -0
- data/webmock-3.26.2/lib/webmock/cucumber.rb +12 -0
- data/webmock-3.26.2/lib/webmock/deprecation.rb +11 -0
- data/webmock-3.26.2/lib/webmock/errors.rb +19 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +228 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/curb_adapter.rb +354 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +239 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/excon_adapter.rb +167 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_lib_adapter.rb +9 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +21 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/client.rb +17 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/request.rb +28 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/response.rb +95 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/streamer.rb +44 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/webmock.rb +77 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb_adapter.rb +39 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/httpclient_adapter.rb +260 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/manticore_adapter.rb +147 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/net_http.rb +310 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/net_http_response.rb +36 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/patron_adapter.rb +132 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +190 -0
- data/webmock-3.26.2/lib/webmock/matchers/any_arg_matcher.rb +15 -0
- data/webmock-3.26.2/lib/webmock/matchers/hash_argument_matcher.rb +23 -0
- data/webmock-3.26.2/lib/webmock/matchers/hash_excluding_matcher.rb +17 -0
- data/webmock-3.26.2/lib/webmock/matchers/hash_including_matcher.rb +19 -0
- data/webmock-3.26.2/lib/webmock/minitest.rb +43 -0
- data/webmock-3.26.2/lib/webmock/rack_response.rb +73 -0
- data/webmock-3.26.2/lib/webmock/request_body_diff.rb +66 -0
- data/webmock-3.26.2/lib/webmock/request_execution_verifier.rb +79 -0
- data/webmock-3.26.2/lib/webmock/request_pattern.rb +428 -0
- data/webmock-3.26.2/lib/webmock/request_registry.rb +37 -0
- data/webmock-3.26.2/lib/webmock/request_signature.rb +56 -0
- data/webmock-3.26.2/lib/webmock/request_signature_snippet.rb +63 -0
- data/webmock-3.26.2/lib/webmock/request_stub.rb +134 -0
- data/webmock-3.26.2/lib/webmock/response.rb +161 -0
- data/webmock-3.26.2/lib/webmock/responses_sequence.rb +42 -0
- data/webmock-3.26.2/lib/webmock/rspec/matchers/request_pattern_matcher.rb +80 -0
- data/webmock-3.26.2/lib/webmock/rspec/matchers/webmock_matcher.rb +69 -0
- data/webmock-3.26.2/lib/webmock/rspec/matchers.rb +29 -0
- data/webmock-3.26.2/lib/webmock/rspec.rb +44 -0
- data/webmock-3.26.2/lib/webmock/stub_registry.rb +84 -0
- data/webmock-3.26.2/lib/webmock/stub_request_snippet.rb +40 -0
- data/webmock-3.26.2/lib/webmock/test_unit.rb +22 -0
- data/webmock-3.26.2/lib/webmock/util/hash_counter.rb +45 -0
- data/webmock-3.26.2/lib/webmock/util/hash_keys_stringifier.rb +27 -0
- data/webmock-3.26.2/lib/webmock/util/hash_validator.rb +19 -0
- data/webmock-3.26.2/lib/webmock/util/headers.rb +77 -0
- data/webmock-3.26.2/lib/webmock/util/parsers/json.rb +72 -0
- data/webmock-3.26.2/lib/webmock/util/parsers/parse_error.rb +7 -0
- data/webmock-3.26.2/lib/webmock/util/parsers/xml.rb +16 -0
- data/webmock-3.26.2/lib/webmock/util/query_mapper.rb +283 -0
- data/webmock-3.26.2/lib/webmock/util/uri.rb +113 -0
- data/webmock-3.26.2/lib/webmock/util/values_stringifier.rb +22 -0
- data/webmock-3.26.2/lib/webmock/util/version_checker.rb +113 -0
- data/webmock-3.26.2/lib/webmock/version.rb +5 -0
- data/webmock-3.26.2/lib/webmock/webmock.rb +175 -0
- data/webmock-3.26.2/lib/webmock.rb +61 -0
- metadata +106 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require 'excon'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
# excon not found
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
if defined?(Excon)
|
|
10
|
+
WebMock::VersionChecker.new('Excon', Excon::VERSION, '0.27.5').check_version!
|
|
11
|
+
|
|
12
|
+
module WebMock
|
|
13
|
+
module HttpLibAdapters
|
|
14
|
+
|
|
15
|
+
class ExconAdapter < HttpLibAdapter
|
|
16
|
+
PARAMS_TO_DELETE = [:expects, :idempotent,
|
|
17
|
+
:instrumentor_name, :instrumentor,
|
|
18
|
+
:response_block,
|
|
19
|
+
:__construction_args, :stack,
|
|
20
|
+
:connection, :response]
|
|
21
|
+
|
|
22
|
+
adapter_for :excon
|
|
23
|
+
|
|
24
|
+
instance_exec do
|
|
25
|
+
@original_excon_mock_default = nil
|
|
26
|
+
@stub = nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.enable!
|
|
30
|
+
self.add_excon_stub
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.disable!
|
|
34
|
+
self.remove_excon_stub
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.add_excon_stub
|
|
38
|
+
if not @stub
|
|
39
|
+
@original_excon_mock_default = ::Excon.defaults[:mock]
|
|
40
|
+
::Excon.defaults[:mock] = true
|
|
41
|
+
@stub = ::Excon.stub({}) do |params|
|
|
42
|
+
self.handle_request(params)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.remove_excon_stub
|
|
48
|
+
::Excon.defaults[:mock] = @original_excon_mock_default
|
|
49
|
+
@original_excon_mock_default = nil
|
|
50
|
+
Excon.stubs.delete(@stub)
|
|
51
|
+
@stub = nil
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.handle_request(params)
|
|
55
|
+
mock_request = self.build_request params.dup
|
|
56
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(mock_request)
|
|
57
|
+
|
|
58
|
+
if mock_response = WebMock::StubRegistry.instance.response_for_request(mock_request)
|
|
59
|
+
self.perform_callbacks(mock_request, mock_response, real_request: false)
|
|
60
|
+
response = self.real_response(mock_response)
|
|
61
|
+
response
|
|
62
|
+
elsif WebMock.net_connect_allowed?(mock_request.uri)
|
|
63
|
+
conn = new_excon_connection(params)
|
|
64
|
+
real_response = conn.request(request_params_from(params.merge(mock: false)))
|
|
65
|
+
|
|
66
|
+
ExconAdapter.perform_callbacks(mock_request, ExconAdapter.mock_response(real_response), real_request: true)
|
|
67
|
+
|
|
68
|
+
real_response.data
|
|
69
|
+
else
|
|
70
|
+
raise WebMock::NetConnectNotAllowedError.new(mock_request)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.new_excon_connection(params)
|
|
75
|
+
# Ensure the connection is constructed with the exact same args
|
|
76
|
+
# that the orginal connection was constructed with.
|
|
77
|
+
args = params.fetch(:__construction_args)
|
|
78
|
+
::Excon::Connection.new(connection_params_from args.merge(mock: false))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def self.connection_params_from(hash)
|
|
82
|
+
hash = hash.dup
|
|
83
|
+
PARAMS_TO_DELETE.each { |key| hash.delete(key) }
|
|
84
|
+
hash
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def self.request_params_from(hash)
|
|
88
|
+
hash = hash.dup
|
|
89
|
+
if defined?(Excon::VALID_REQUEST_KEYS)
|
|
90
|
+
hash.reject! {|key,_| !Excon::VALID_REQUEST_KEYS.include?(key) }
|
|
91
|
+
end
|
|
92
|
+
PARAMS_TO_DELETE.each { |key| hash.delete(key) }
|
|
93
|
+
hash
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.to_query(hash)
|
|
97
|
+
string = "".dup
|
|
98
|
+
for key, values in hash
|
|
99
|
+
if values.nil?
|
|
100
|
+
string << key.to_s << '&'
|
|
101
|
+
else
|
|
102
|
+
for value in [*values]
|
|
103
|
+
string << key.to_s << '=' << CGI.escape(value.to_s) << '&'
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
string.chop! # remove trailing '&'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def self.build_request(params)
|
|
111
|
+
params = params.dup
|
|
112
|
+
params.delete(:user)
|
|
113
|
+
params.delete(:password)
|
|
114
|
+
method = (params.delete(:method) || :get).to_s.downcase.to_sym
|
|
115
|
+
params[:query] = to_query(params[:query]) if params[:query].is_a?(Hash)
|
|
116
|
+
uri = Addressable::URI.new(params).to_s
|
|
117
|
+
WebMock::RequestSignature.new method, uri, body: body_from(params), headers: params[:headers]
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def self.body_from(params)
|
|
121
|
+
body = params[:body]
|
|
122
|
+
return body unless body.respond_to?(:read)
|
|
123
|
+
|
|
124
|
+
contents = body.read
|
|
125
|
+
body.rewind if body.respond_to?(:rewind)
|
|
126
|
+
contents
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def self.real_response(mock)
|
|
130
|
+
raise Excon::Errors::Timeout if mock.should_timeout
|
|
131
|
+
mock.raise_error_if_any
|
|
132
|
+
{
|
|
133
|
+
body: mock.body,
|
|
134
|
+
status: mock.status[0].to_i,
|
|
135
|
+
reason_phrase: mock.status[1],
|
|
136
|
+
headers: mock.headers || {}
|
|
137
|
+
}
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def self.mock_response(real)
|
|
141
|
+
mock = WebMock::Response.new
|
|
142
|
+
mock.status = [real.status, real.reason_phrase]
|
|
143
|
+
mock.headers = real.headers
|
|
144
|
+
mock.body = real.body.dup
|
|
145
|
+
mock
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def self.perform_callbacks(request, response, options = {})
|
|
149
|
+
return unless WebMock::CallbackRegistry.any_callbacks?
|
|
150
|
+
WebMock::CallbackRegistry.invoke_callbacks(options.merge(lib: :excon), request, response)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
Excon::Connection.class_eval do
|
|
157
|
+
def self.new(args = {})
|
|
158
|
+
args.delete(:__construction_args)
|
|
159
|
+
super(args).tap do |instance|
|
|
160
|
+
instance.data[:__construction_args] = args
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Suppresses Excon connection argument validation warning
|
|
166
|
+
Excon::VALID_CONNECTION_KEYS << :__construction_args
|
|
167
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WebMock
|
|
4
|
+
class HttpLibAdapterRegistry
|
|
5
|
+
include Singleton
|
|
6
|
+
|
|
7
|
+
attr_accessor :http_lib_adapters
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@http_lib_adapters = {}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def register(lib, adapter)
|
|
14
|
+
@http_lib_adapters[lib] = adapter
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def each_adapter(&block)
|
|
18
|
+
@http_lib_adapters.each(&block)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module HTTP
|
|
4
|
+
class Client
|
|
5
|
+
alias_method :__perform__, :perform
|
|
6
|
+
|
|
7
|
+
def perform(request, options)
|
|
8
|
+
return __perform__(request, options) unless webmock_enabled?
|
|
9
|
+
|
|
10
|
+
WebMockPerform.new(request, options) { __perform__(request, options) }.exec
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def webmock_enabled?
|
|
14
|
+
::WebMock::HttpLibAdapters::HttpRbAdapter.enabled?
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module HTTP
|
|
4
|
+
class Request
|
|
5
|
+
def webmock_signature
|
|
6
|
+
request_body = nil
|
|
7
|
+
|
|
8
|
+
if defined?(HTTP::Request::Body)
|
|
9
|
+
request_body = String.new
|
|
10
|
+
first_chunk_encoding = nil
|
|
11
|
+
body.each do |part|
|
|
12
|
+
request_body << part
|
|
13
|
+
first_chunk_encoding ||= part.encoding
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
request_body.force_encoding(first_chunk_encoding) if first_chunk_encoding
|
|
17
|
+
request_body
|
|
18
|
+
else
|
|
19
|
+
request_body = body
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
::WebMock::RequestSignature.new(verb, uri.to_s, {
|
|
23
|
+
headers: headers.to_h,
|
|
24
|
+
body: request_body
|
|
25
|
+
})
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module HTTP
|
|
4
|
+
class Response
|
|
5
|
+
def to_webmock
|
|
6
|
+
webmock_response = ::WebMock::Response.new
|
|
7
|
+
|
|
8
|
+
webmock_response.status = [status.to_i, reason]
|
|
9
|
+
|
|
10
|
+
webmock_response.body = body.to_s
|
|
11
|
+
# This call is used to reset the body of the response to enable it to be streamed if necessary.
|
|
12
|
+
# The `body.to_s` call above reads the body, which allows WebMock to trigger any registered callbacks.
|
|
13
|
+
# However, once the body is read to_s, it cannot be streamed again and attempting to do so
|
|
14
|
+
# will raise a "HTTP::StateError: body has already been consumed" error.
|
|
15
|
+
# To avoid this error, we replace the original body with a new one.
|
|
16
|
+
# The new body has its @stream attribute set to new Streamer, instead of the original Connection.
|
|
17
|
+
# Unfortunately, it's not possible to reset the original body to its initial streaming state.
|
|
18
|
+
# Therefore, this replacement is the best workaround currently available.
|
|
19
|
+
reset_body_to_allow_it_to_be_streamed!(webmock_response)
|
|
20
|
+
|
|
21
|
+
webmock_response.headers = headers.to_h
|
|
22
|
+
webmock_response
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class << self
|
|
26
|
+
def from_webmock(request, webmock_response, request_signature = nil)
|
|
27
|
+
status = Status.new(webmock_response.status.first)
|
|
28
|
+
headers = webmock_response.headers || {}
|
|
29
|
+
uri = normalize_uri(request_signature && request_signature.uri)
|
|
30
|
+
|
|
31
|
+
body = build_http_rb_response_body_from_webmock_response(webmock_response)
|
|
32
|
+
|
|
33
|
+
return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
|
|
34
|
+
|
|
35
|
+
# 5.0.0 had a breaking change to require request instead of uri.
|
|
36
|
+
if HTTP::VERSION < '5.0.0'
|
|
37
|
+
return new({
|
|
38
|
+
status: status,
|
|
39
|
+
version: "1.1",
|
|
40
|
+
headers: headers,
|
|
41
|
+
body: body,
|
|
42
|
+
uri: uri
|
|
43
|
+
})
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# 6.0.0 changed Response.new from a positional hash to keyword arguments.
|
|
47
|
+
if HTTP::VERSION >= '6.0.0'
|
|
48
|
+
return new(
|
|
49
|
+
status: status,
|
|
50
|
+
version: "1.1",
|
|
51
|
+
headers: headers,
|
|
52
|
+
body: body,
|
|
53
|
+
request: request,
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
new({
|
|
58
|
+
status: status,
|
|
59
|
+
version: "1.1",
|
|
60
|
+
headers: headers,
|
|
61
|
+
body: body,
|
|
62
|
+
request: request,
|
|
63
|
+
})
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def build_http_rb_response_body_from_webmock_response(webmock_response)
|
|
67
|
+
if HTTP::VERSION < "1.0.0"
|
|
68
|
+
Body.new(Streamer.new(webmock_response.body))
|
|
69
|
+
elsif HTTP::VERSION < "3.0.0"
|
|
70
|
+
Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
|
|
71
|
+
else
|
|
72
|
+
Body.new(
|
|
73
|
+
Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
|
|
74
|
+
encoding: webmock_response.body.encoding
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def normalize_uri(uri)
|
|
80
|
+
return unless uri
|
|
81
|
+
|
|
82
|
+
uri = Addressable::URI.parse uri
|
|
83
|
+
uri.port = nil if uri.default_port && uri.port == uri.default_port
|
|
84
|
+
|
|
85
|
+
uri
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
def reset_body_to_allow_it_to_be_streamed!(webmock_response)
|
|
92
|
+
@body = self.class.build_http_rb_response_body_from_webmock_response(webmock_response)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module HTTP
|
|
4
|
+
class Response
|
|
5
|
+
class Streamer
|
|
6
|
+
def initialize(str, encoding: Encoding::BINARY)
|
|
7
|
+
@io = StringIO.new str
|
|
8
|
+
@encoding = encoding
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def readpartial(size = nil, outbuf = nil)
|
|
12
|
+
unless size
|
|
13
|
+
if defined?(HTTP::Connection::BUFFER_SIZE)
|
|
14
|
+
size = HTTP::Connection::BUFFER_SIZE
|
|
15
|
+
elsif defined?(HTTP::Client::BUFFER_SIZE)
|
|
16
|
+
size = HTTP::Client::BUFFER_SIZE
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
chunk = @io.read(size, outbuf)
|
|
21
|
+
|
|
22
|
+
# HTTP.rb 6.0+ expects EOFError at end-of-stream instead of nil
|
|
23
|
+
if chunk.nil?
|
|
24
|
+
raise EOFError if HTTP::VERSION >= "6.0.0"
|
|
25
|
+
return nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
chunk.force_encoding(@encoding)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def close
|
|
32
|
+
@io.close
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def finished_request?
|
|
36
|
+
@io.eof?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def sequence_id
|
|
40
|
+
-1
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module HTTP
|
|
4
|
+
class WebMockPerform
|
|
5
|
+
def initialize(request, options, &perform)
|
|
6
|
+
@request = request
|
|
7
|
+
@options = options
|
|
8
|
+
@perform = perform
|
|
9
|
+
@request_signature = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def exec
|
|
13
|
+
replay || perform || halt
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def request_signature
|
|
17
|
+
unless @request_signature
|
|
18
|
+
@request_signature = @request.webmock_signature
|
|
19
|
+
register_request(@request_signature)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@request_signature
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
protected
|
|
26
|
+
|
|
27
|
+
def response_for_request(signature)
|
|
28
|
+
::WebMock::StubRegistry.instance.response_for_request(signature)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def register_request(signature)
|
|
32
|
+
::WebMock::RequestRegistry.instance.requested_signatures.put(signature)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def replay
|
|
36
|
+
webmock_response = response_for_request request_signature
|
|
37
|
+
|
|
38
|
+
return unless webmock_response
|
|
39
|
+
|
|
40
|
+
raise_timeout_error if webmock_response.should_timeout
|
|
41
|
+
webmock_response.raise_error_if_any
|
|
42
|
+
|
|
43
|
+
invoke_callbacks(webmock_response, real_request: false)
|
|
44
|
+
response = ::HTTP::Response.from_webmock @request, webmock_response, request_signature
|
|
45
|
+
|
|
46
|
+
# HTTP.rb 6.0+ wraps responses in reverse feature order
|
|
47
|
+
features = @options.features.values
|
|
48
|
+
features = features.reverse if HTTP::VERSION >= "6.0.0"
|
|
49
|
+
features.each { |feature| response = feature.wrap_response(response) }
|
|
50
|
+
response
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def raise_timeout_error
|
|
54
|
+
raise Errno::ETIMEDOUT if HTTP::VERSION < "1.0.0"
|
|
55
|
+
raise HTTP::TimeoutError, "connection error: #{Errno::ETIMEDOUT.new}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def perform
|
|
59
|
+
return unless ::WebMock.net_connect_allowed?(request_signature.uri)
|
|
60
|
+
response = @perform.call
|
|
61
|
+
invoke_callbacks(response.to_webmock, real_request: true)
|
|
62
|
+
response
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def halt
|
|
66
|
+
raise ::WebMock::NetConnectNotAllowedError.new request_signature
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def invoke_callbacks(webmock_response, options = {})
|
|
70
|
+
::WebMock::CallbackRegistry.invoke_callbacks(
|
|
71
|
+
options.merge({ lib: :http_rb }),
|
|
72
|
+
request_signature,
|
|
73
|
+
webmock_response
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require "http"
|
|
5
|
+
rescue LoadError
|
|
6
|
+
# HTTP gem not found
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
if defined?(HTTP) && defined?(HTTP::VERSION)
|
|
10
|
+
WebMock::VersionChecker.new("HTTP Gem", HTTP::VERSION, "0.6.0").check_version!
|
|
11
|
+
|
|
12
|
+
module WebMock
|
|
13
|
+
module HttpLibAdapters
|
|
14
|
+
class HttpRbAdapter < HttpLibAdapter
|
|
15
|
+
adapter_for :http_rb
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
def enable!
|
|
19
|
+
@enabled = true
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def disable!
|
|
23
|
+
@enabled = false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def enabled?
|
|
27
|
+
@enabled
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
require_relative "http_rb/client"
|
|
35
|
+
require_relative "http_rb/request"
|
|
36
|
+
require_relative "http_rb/response"
|
|
37
|
+
require_relative "http_rb/streamer"
|
|
38
|
+
require_relative "http_rb/webmock"
|
|
39
|
+
end
|