Class: Dialed::HTTP::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/dialed/http/response.rb

Defined Under Namespace

Classes: Body, EveryBody, JsonBody

Instance Method Summary collapse

Constructor Details

#initialize(internal_response) ⇒ Response

Returns a new instance of Response.



19
20
21
22
23
# File 'lib/dialed/http/response.rb', line 19

def initialize(internal_response)
  @internal_response = internal_response
  @notifier = Async::Notification.new
  buffer!
end

Instance Method Details

#bodyObject



25
26
27
# File 'lib/dialed/http/response.rb', line 25

def body
  @body ||= body_klass.new(internal_response.body)
end

#body_klassObject



29
30
31
32
33
34
35
36
# File 'lib/dialed/http/response.rb', line 29

def body_klass
  case headers
  in { 'content-type': 'application/json' }
    JsonBody
  else
    EveryBody
  end
end

#buffer!Object



38
39
40
# File 'lib/dialed/http/response.rb', line 38

def buffer!
  @internal_response.buffered!
end

#headersObject



50
51
52
53
54
55
# File 'lib/dialed/http/response.rb', line 50

def headers
  @headers ||= internal_response
                 &.headers
                 &.to_h
                 &.transform_keys(&:to_sym)
end

#http11?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dialed/http/response.rb', line 46

def http11?
  internal_response.version == 'HTTP/1.1'
end

#http2?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/dialed/http/response.rb', line 42

def http2?
  internal_response.version == 'HTTP/2'
end