class SFML::Network::Http::Response
Read-only view onto a CSFML sfHttpResponse. Wraps the C pointer in a Ruby object that destroys the response when GCād.
Constants
- 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).
Public Class Methods
Source
# File lib/sfml/network/http.rb, line 119 def self._take_ownership(ptr) obj = allocate obj.instance_variable_set(:@handle, FFI::AutoPointer.new(ptr, C::Network.method(:sfHttpResponse_destroy))) obj end
@!visibility private
Source
# File lib/sfml/network/http.rb, line 87 def initialize raise NoMethodError, "use SFML::Network::Http#send_request to create a Response" end
Responses are created via Http#send_request, not directly.
Public Instance Methods
Source
# 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). def field(name) = C::Network.sfHttpResponse_getField(@handle, name.to_s) # HTTP version the server replied with, as `[major, minor]`. def http_version [ C::Network.sfHttpResponse_getMajorVersion(@handle), C::Network.sfHttpResponse_getMinorVersion(@handle), ] end attr_reader :handle # :nodoc: # @!visibility private def self._take_ownership(ptr) obj = allocate obj.instance_variable_set(:@handle, FFI::AutoPointer.new(ptr, C::Network.method(:sfHttpResponse_destroy))) obj end end end
Response body as a Ruby String.
Source
# File lib/sfml/network/http.rb, line 106 def field(name) = C::Network.sfHttpResponse_getField(@handle, name.to_s) # HTTP version the server replied with, as `[major, minor]`. def http_version [ C::Network.sfHttpResponse_getMajorVersion(@handle), C::Network.sfHttpResponse_getMinorVersion(@handle), ] end attr_reader :handle # :nodoc: # @!visibility private def self._take_ownership(ptr) obj = allocate obj.instance_variable_set(:@handle, FFI::AutoPointer.new(ptr, C::Network.method(:sfHttpResponse_destroy))) obj end end
Source
# File lib/sfml/network/http.rb, line 109 def http_version [ C::Network.sfHttpResponse_getMajorVersion(@handle), C::Network.sfHttpResponse_getMinorVersion(@handle), ] end
HTTP version the server replied with, as [major, minor].
Source
# File lib/sfml/network/http.rb, line 93 def status C::Network.sfHttpResponse_getStatus(@handle) end
Numeric HTTP status code (200, 404, ā¦). Combine with STATUS_NAMES or use status_symbol.
Source
# File lib/sfml/network/http.rb, line 99 def status_symbol STATUS_NAMES[status] || status end
The status as a symbol when CSFML maps it, otherwise the raw integer. Useful for case resp.status_symbol in :ok.