Class: Cybertrain::HttpClient::Response

Inherits:
Object
  • Object
show all
Defined in:
cybertrain/http_client.rb

Overview

A response: the status, the headers (names in lowercase) and the body.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#body ⇒ String (readonly)

The body as received (chunked transfer coding removed), a byte String: binary under CRuby, as Net::HTTP’s is.

Returns:

  • (String)


107
108
109
# File 'cybertrain/http_client.rb', line 107

def body
  @body
end

#headers ⇒ Hash{String => String} (readonly)

Header names are lowercase; a header sent more than once has its values joined with “, “.

Returns:

  • (Hash{String => String})


101
102
103
# File 'cybertrain/http_client.rb', line 101

def headers
  @headers
end

#status ⇒ Integer (readonly)

Returns e.g. 200.

Returns:

  • (Integer) —

    e.g. 200



95
96
97
# File 'cybertrain/http_client.rb', line 95

def status
  @status
end

Instance Method Details

#header(name) ⇒ String?

Parameters:

  • name (String) —

    any case

Returns:

  • (String, nil)


118
119
120
# File 'cybertrain/http_client.rb', line 118

def header(name)
  @headers[name.to_s.downcase]
end

#success? ⇒ Boolean

Returns true for a 2xx status.

Returns:

  • (Boolean) —

    true for a 2xx status



124
125
126
# File 'cybertrain/http_client.rb', line 124

def success?
  @status >= 200 && @status <= 299
end