Module: WebMock::HttpLibAdapters::Plugin
- Defined in:
- lib/httpx/adapters/webmock.rb
Overview
HTTPX plugin for webmock.
Requests are “hijacked” at the session, before they’re distributed to a connection.
Defined Under Namespace
Modules: ConnectionMethods, InstanceMethods, ResponseBodyMethods, ResponseMethods
Class Method Summary
collapse
Class Method Details
.build_error_response(request, exception) ⇒ Object
49
50
51
|
# File 'lib/httpx/adapters/webmock.rb', line 49
def build_error_response(request, exception)
HTTPX::ErrorResponse.new(request, exception)
end
|
.build_from_webmock_response(request, webmock_response) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/httpx/adapters/webmock.rb', line 36
def build_from_webmock_response(request, webmock_response)
return build_error_response(request, HTTPX::TimeoutError.new(1, "Timed out")) if webmock_response.should_timeout
return build_error_response(request, webmock_response.exception) if webmock_response.exception
request.options.response_class.new(request,
webmock_response.status[0],
"2.0",
webmock_response.).tap do |res|
res.mocked = true
end
end
|
.build_webmock_request_signature(request) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/httpx/adapters/webmock.rb', line 15
def build_webmock_request_signature(request)
uri = WebMock::Util::URI.heuristic_parse(request.uri)
uri.query = request.query
uri.path = uri.normalized_path.gsub("[^:]//", "/")
WebMock::RequestSignature.new(
request.verb.downcase.to_sym,
uri.to_s,
body: request.body.to_s,
headers: request..to_h
)
end
|
.build_webmock_response(_request, response) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/httpx/adapters/webmock.rb', line 28
def build_webmock_response(_request, response)
webmock_response = WebMock::Response.new
webmock_response.status = [response.status, HTTP_REASONS[response.status]]
webmock_response.body = response.body.to_s
webmock_response. = response..to_h
webmock_response
end
|