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



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

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



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

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

.get_webmock_response(request) ⇒ Object



193
194
195
196
# File 'lib/webmock/http_lib_adapters/async_http_client_adapter.rb', line 193

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