Class: SFML::Network::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/sfml/network/http.rb

Overview

Read-only view onto a CSFML sfHttpResponse. Wraps the C pointer in a Ruby object that destroys the response when GC'd.

Constant Summary collapse

STATUS_NAMES =

Status mappings — most map onto standard HTTP codes; the four at the bottom are SFML-side transport errors above the standard range (≥ 1000).

{
  200 => :ok, 201 => :created, 202 => :accepted, 204 => :no_content,
  205 => :reset_content, 206 => :partial_content,
  301 => :multiple_choices, 302 => :moved_permanently, 303 => :moved_temporarily,
  304 => :not_modified,
  400 => :bad_request, 401 => :unauthorized, 403 => :forbidden, 404 => :not_found,
  405 => :range_not_satisfiable,
  500 => :internal_server_error, 501 => :not_implemented, 502 => :bad_gateway,
  503 => :service_not_available, 504 => :gateway_timeout, 505 => :version_not_supported,
  1000 => :invalid_response, 1001 => :connection_failed,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Response

Responses are created via Http#send_request, not directly.

Raises:

  • (NoMethodError)


87
88
89
# File 'lib/sfml/network/http.rb', line 87

def initialize
  raise NoMethodError, "use SFML::Network::Http#send_request to create a Response"
end

Instance Attribute Details

#handle ⇒ Object (readonly)

:nodoc:



116
117
118
# File 'lib/sfml/network/http.rb', line 116

def handle
  @handle
end

Instance Method Details

#body ⇒ Object

Response body as a Ruby String.



104
105
# File 'lib/sfml/network/http.rb', line 104

def body  = C::Network.sfHttpResponse_getBody(@handle).to_s
# Look up a response header by name (case-insensitive in HTTP).

#field(name) ⇒ Object

Look up a response header by name (case-insensitive in HTTP).



106
# File 'lib/sfml/network/http.rb', line 106

def field(name) = C::Network.sfHttpResponse_getField(@handle, name.to_s)

#http_version ⇒ Object

HTTP version the server replied with, as [major, minor].



109
110
111
112
113
114
# File 'lib/sfml/network/http.rb', line 109

def http_version
  [
    C::Network.sfHttpResponse_getMajorVersion(@handle),
    C::Network.sfHttpResponse_getMinorVersion(@handle),
  ]
end

#status ⇒ Object

Numeric HTTP status code (200, 404, ...). Combine with STATUS_NAMES or use #status_symbol.



93
94
95
# File 'lib/sfml/network/http.rb', line 93

def status
  C::Network.sfHttpResponse_getStatus(@handle)
end

#status_symbol ⇒ Object

The status as a symbol when CSFML maps it, otherwise the raw integer. Useful for case resp.status_symbol in :ok.



99
100
101
# File 'lib/sfml/network/http.rb', line 99

def status_symbol
  STATUS_NAMES[status] || status
end