Class: Async::HTTP::WebMockClientWrapper
- Inherits:
-
Client
- Object
- Client
- Async::HTTP::WebMockClientWrapper
- Defined in:
- lib/webmock/http_lib_adapters/async_http_client_adapter.rb
Instance Method Summary collapse
- #call(request) ⇒ Object
- #close ⇒ Object
-
#initialize(endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme, authority: endpoint.authority, **options) ⇒ WebMockClientWrapper
constructor
A new instance of WebMockClientWrapper.
Constructor Details
#initialize(endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme, authority: endpoint.authority, **options) ⇒ WebMockClientWrapper
Returns a new instance of WebMockClientWrapper.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/webmock/http_lib_adapters/async_http_client_adapter.rb', line 47 def initialize( endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme, authority: endpoint., ** ) webmock_endpoint = WebMockEndpoint.new(scheme, , protocol) @network_client = WebMockClient.new(endpoint, **) @webmock_client = WebMockClient.new(webmock_endpoint, **) @endpoint = endpoint @scheme = scheme @authority = end |
Instance Method Details
#call(request) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/webmock/http_lib_adapters/async_http_client_adapter.rb', line 64 def call(request) request.scheme ||= self.scheme request. ||= self. request_signature = build_request_signature(request) WebMock::RequestRegistry.instance.requested_signatures.put(request_signature) webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature) net_connect_allowed = WebMock.net_connect_allowed?(request_signature.uri) real_request = false if webmock_response webmock_response.raise_error_if_any raise Async::TimeoutError, 'WebMock timeout error' if webmock_response.should_timeout WebMockApplication.add_webmock_response(request, webmock_response) response = @webmock_client.call(request) elsif net_connect_allowed response = @network_client.call(request) real_request = true else raise WebMock::NetConnectNotAllowedError.new(request_signature) unless webmock_response end if WebMock::CallbackRegistry.any_callbacks? webmock_response ||= build_webmock_response(response) WebMock::CallbackRegistry.invoke_callbacks( { lib: :async_http_client, real_request: real_request }, request_signature, webmock_response ) end response end |
#close ⇒ Object
101 102 103 104 |
# File 'lib/webmock/http_lib_adapters/async_http_client_adapter.rb', line 101 def close @network_client.close @webmock_client.close end |