class Halite::Response

Defined in:

halite/response.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(uri : URI, status_code : Int32, body : String? = nil, headers = HTTP::Headers.new, status_message = nil, body_io : IO? = nil, version = "HTTP/1.1", history = [] of Halite::Response) #

def self.new(uri : URI, conn : HTTP::Client::Response, history = [] of Halite::Response) #

Instance Method Detail

def body(*args, **options) #

def body(*args, **options, &) #

def body_io(*args, **options) #

def body_io(*args, **options, &) #

def charset(*args, **options) #

def charset(*args, **options, &) #

def conn : HTTP::Client::Response #

def content_length : Int64? #

Content Length


def content_type(*args, **options) #

def content_type(*args, **options, &) #

def cookies : HTTP::Cookies? #

Return a HTTP::Cookies of parsed cookie headers or else nil.


def filename : String? #

Return filename if it exists, else Nil.


def headers(*args, **options) #

def headers(*args, **options, &) #

def history : Array(Response) #

def inspect #
Description copied from class Object

Returns a String representation of this object suitable to be embedded inside other expressions, sometimes providing more information about this object.

#inspect (and #inspect(io)) are the methods used when you invoke #to_s or #inspect on an object that holds other objects and wants to show them. For example when you invoke Array#to_s, #inspect will be invoked on each element:

ary = ["one", "two", "three, etc."]
ary.inspect # => ["one", "two", "three, etc."]

Note that if Array invoked #to_s on each of the elements above, the output would have been this:

ary = ["one", "two", "three, etc."]
# If inspect invoked to_s on each element...
ary.inspect # => [one, two, three, etc.]

Note that it's not clear how many elements the array has, or which are they, because #to_s doesn't guarantee that the string representation is clearly delimited (in the case of String the quotes are not shown).

Also note that sometimes the output of #inspect will look like a Crystal expression that will compile, but this isn't always the case, nor is it necessary. Notably, Reference#inspect and Struct#inspect return values that don't compile.

Classes must usually not override this method. Instead, they must override inspect(io), which must append to the given IO object.


def links : Hash(String, Halite::HeaderLink)? #

Return a list of parsed link headers proxies or else nil.


def parse(name : String? = nil) #

Parse response body with corresponding MIME type adapter.


def raise_for_status #

Raise Halite::ClientError/Halite::ServerError if one occurred.

  • 4XX raise an Halite::ClientError exception
  • 5XX raise an Halite::ServerError exception
  • return nil with other status code
Halite.get("https://httpbin.org/status/404").raise_for_status
# => Unhandled exception: 404 not found error with url: https://httpbin.org/status/404  (Halite::ClientError)

Halite.get("https://httpbin.org/status/500", params: {"foo" => "bar"}).raise_for_status
# => Unhandled exception: 500 internal server error error with url: https://httpbin.org/status/500?foo=bar  (Halite::ServerError)

Halite.get("https://httpbin.org/status/301").raise_for_status
# => nil

def rate_limit : Halite::RateLimit? #

def status_code(*args, **options) #

def status_code(*args, **options, &) #

def status_message(*args, **options) #

def status_message(*args, **options, &) #

def success?(*args, **options) #

def success?(*args, **options, &) #

def to_a #

Return status_code, headers and body in a array


def to_raw #

Return raw of response


def to_s(io) #

def to_s #

Return String eagerly consume the entire body as a string


def uri : URI #

def version(*args, **options) #

def version(*args, **options, &) #