109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/httpx/adapters/webmock.rb', line 109
def send(request)
request_signature = Plugin.build_webmock_request_signature(request)
WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
if (mock_response = WebMock::StubRegistry.instance.response_for_request(request_signature))
response = Plugin.build_from_webmock_response(request, mock_response)
WebMock::CallbackRegistry.invoke_callbacks({ lib: :httpx }, request_signature, mock_response)
log { "mocking #{request.uri} with #{mock_response.inspect}" }
request.response = response
request.emit(:response, response)
response << mock_response.body.dup unless response.is_a?(HTTPX::ErrorResponse)
elsif WebMock.net_connect_allowed?(request_signature.uri)
if WebMock::CallbackRegistry.any_callbacks?
request.on(:response) do |resp|
unless resp.is_a?(HTTPX::ErrorResponse)
webmock_response = Plugin.build_webmock_response(request, resp)
WebMock::CallbackRegistry.invoke_callbacks(
{ lib: :httpx, real_request: true }, request_signature,
webmock_response
)
end
end
end
@mocked = false
emit(:unmock_connection, self)
super
else
raise WebMock::NetConnectNotAllowedError, request_signature
end
end
|