Class: WebMock::HttpLibAdapters::WebMockNetHttp2Client

Inherits:
NetHttp2::Client
  • Object
show all
Defined in:
lib/faraday/net_http2/webmock_adapter.rb

Instance Method Summary collapse

Instance Method Details

#call(method, path, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/faraday/net_http2/webmock_adapter.rb', line 9

def call(method, path, options={})
  request = prepare_request(method, path, options)

  request_signature = WebMock::RequestSignature.new method, request.uri, body: request.body, headers: request.headers
  WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)

  if (mock_response = WebMock::StubRegistry.instance.response_for_request(request_signature))
    raise Errno::ETIMEDOUT if mock_response.should_timeout
    response = NetHttp2::Response.new(
      headers: { ":status" => mock_response.status[0] }.merge(mock_response.headers || {}),
      body:    mock_response.body
    )

    WebMock::CallbackRegistry.invoke_callbacks({ lib: :net_http2 }, request_signature, mock_response)
    response
  elsif WebMock.net_connect_allowed?(request_signature.uri)
    super
  else
    raise WebMock::NetConnectNotAllowedError, request_signature
  end
end