class Seahorse::Client::Http::AsyncResponse

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method Seahorse::Client::Http::Response::new
# File lib/seahorse/client/http/async_response.rb, line 8
def initialize(options = {})
  super
end

Public Instance Methods

signal_done(options = {}) click to toggle source
# File lib/seahorse/client/http/async_response.rb, line 24
def signal_done(options = {})
  # H2 only has header and body
  # ':status' header will be sent back
  if options.keys.sort == [:body, :headers]
    signal_headers(options[:headers])
    signal_data(options[:body])
    signal_done
  elsif options.empty?
    @body.rewind if @body.respond_to?(:rewind)
    @done = true
    emit(:done)
  else
    msg = "options must be empty or must contain :headers and :body"
    raise ArgumentError, msg
  end
end
signal_headers(headers) click to toggle source
# File lib/seahorse/client/http/async_response.rb, line 12
def signal_headers(headers)
  # H2 headers arrive as array of pair
  hash = headers.inject({}) do |h, pair|
    key, value = pair
    h[key] = value
    h
  end
  @status_code = hash[":status"].to_i
  @headers = Headers.new(hash)
  emit(:headers, @status_code, @headers)
end