Class: Aws::Plugins::StubResponses::Handler Private

Inherits:
Seahorse::Client::Handler show all
Defined in:
lib/aws-sdk-core/plugins/stub_responses.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary

Attributes inherited from Seahorse::Client::Handler

#handler

Instance Method Summary collapse

Methods inherited from Seahorse::Client::Handler

#initialize, #inspect

Constructor Details

This class inherits a constructor from Seahorse::Client::Handler

Instance Method Details

#apply_stub(stub, response, async_mode = false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


60
61
62
63
64
65
66
67
# File 'lib/aws-sdk-core/plugins/stub_responses.rb', line 60

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

#call(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


50
51
52
53
54
55
56
57
58
# File 'lib/aws-sdk-core/plugins/stub_responses.rb', line 50

def call(context)
  stub = context.client.next_stub(context)
  resp = Seahorse::Client::Response.new(context: context)
  async_mode = context.client.is_a? Seahorse::Client::AsyncBase
  apply_stub(stub, resp, async_mode)

  async_mode ? Seahorse::Client::AsyncResponse.new(
    context: context, stream: context[:input_event_stream_handler].event_emitter.stream, sync_queue: Queue.new) : resp
end

#signal_error(error, http_resp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


69
70
71
72
73
74
75
# File 'lib/aws-sdk-core/plugins/stub_responses.rb', line 69

def signal_error(error, http_resp)
  if Exception === error
    http_resp.signal_error(error)
  else
    http_resp.signal_error(error.new)
  end
end

#signal_http(stub, http_resp, async_mode = false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/aws-sdk-core/plugins/stub_responses.rb', line 80

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