Module: Async::HTTP::WebMockApplication

Defined in:
lib/webmock/http_lib_adapters/async_http_client_adapter.rb

Constant Summary collapse

WEBMOCK_REQUEST_ID_HEADER =
'x-webmock-request-id'.freeze

Class Method Summary collapse

Class Method Details

.add_webmock_response(request, webmock_response) ⇒ Object


180
181
182
183
184
# File 'lib/webmock/http_lib_adapters/async_http_client_adapter.rb', line 180

def add_webmock_response(request, webmock_response)
  webmock_request_id = request.object_id.to_s
  request.headers.add(WEBMOCK_REQUEST_ID_HEADER, webmock_request_id)
  webmock_responses[webmock_request_id] = webmock_response
end

.call(request) ⇒ Object


174
175
176
177
178
# File 'lib/webmock/http_lib_adapters/async_http_client_adapter.rb', line 174

def call(request)
  request.read
  webmock_response = get_webmock_response(request)
  build_response(webmock_response)
end

.get_webmock_response(request) ⇒ Object


186
187
188
189
# File 'lib/webmock/http_lib_adapters/async_http_client_adapter.rb', line 186

def get_webmock_response(request)
  webmock_request_id = request.headers[WEBMOCK_REQUEST_ID_HEADER][0]
  webmock_responses.fetch(webmock_request_id)
end