class Aws::Plugins::StubResponses::StubbingHandler
Public Instance Methods
Source
# File lib/aws-sdk-core/plugins/stub_responses.rb, line 71 def call(context) span_wrapper(context) do stub_responses(context) end end
Private Instance Methods
Source
# File lib/aws-sdk-core/plugins/stub_responses.rb, line 96 def apply_stub(stub, response, async_mode = false) http_resp = response.context.http_response case when stub[:error] then signal_error(stub[:error], http_resp) when stub[:http] then signal_http(stub[:http], http_resp, async_mode) when stub[:data] then response.data = stub[:data] end end
Source
# File lib/aws-sdk-core/plugins/stub_responses.rb, line 105 def signal_error(error, http_resp) if Exception === error http_resp.signal_error(error) else http_resp.signal_error(error.new) end end
Source
# File lib/aws-sdk-core/plugins/stub_responses.rb, line 116 def signal_http(stub, http_resp, async_mode = false) if async_mode h2_headers = stub.headers.to_h.inject([]) do |arr, (k, v)| arr << [k, v] end h2_headers << [":status", stub.status_code] http_resp.signal_headers(h2_headers) else http_resp.signal_headers(stub.status_code, stub.headers.to_h) end while chunk = stub.body.read(1024 * 1024) http_resp.signal_data(chunk) end stub.body.rewind http_resp.signal_done end
@param [Seahorse::Client::Http::Response] stub @param [Seahorse::Client::Http::Response | Seahorse::Client::Http::AsyncResponse
] http_resp @param [Boolean] async_mode
Source
# File lib/aws-sdk-core/plugins/stub_responses.rb, line 133 def span_wrapper(context, &block) context.tracer.in_span( 'Handler.StubResponses', attributes: Aws::Telemetry.http_request_attrs(context) ) do |span| block.call.tap do span.add_attributes( Aws::Telemetry.http_response_attrs(context) ) end end end
Source
# File lib/aws-sdk-core/plugins/stub_responses.rb, line 79 def stub_responses(context) resp = Seahorse::Client::Response.new(context: context) async_mode = context.client.is_a? Seahorse::Client::AsyncBase stub = context.client.next_stub(context) stub[:mutex].synchronize { apply_stub(stub, resp, async_mode) } if async_mode Seahorse::Client::AsyncResponse.new( context: context, stream: context[:input_event_stream_handler].event_emitter.stream, sync_queue: Queue.new ) else resp end end