View Source BrowseyHttp.Response (BrowseyHttp v0.0.6)
A response from a browser-imitating HTTP request.
Summary
Functions
Converts our headers from a map to a list of 2-tuples in the format used by Finch or HTTPoison.
True if the response appears to be HTML, either based on its headers or its body content.
The original URL passed to BrowseyHttp.get/2
, before any redirects.
Converts headers in the 2-tuple format used by Finch or HTTPoison to a map used by BrowseyHttp.get/2
.
The human readable title for an HTTP error status code.
Types
Headers sent with a request or returned in a response from the server.
Maps response header names (all lowercase, like "content-encoding"
)
to the values associated with that header. This is structured as a map, the way the
Req
library does, to make it clear that servers
may legitimately send multiple values for the same header name.
You can use BrowseyHttp.Response.headers_to_proplist/1
to convert this to the
format used by HTTP clients like Finch or HTTPoison, and you can use
BrowseyHttp.Response.proplist_to_headers/1
to convert from that format to this one.
@type t() :: %BrowseyHttp.Response{ body: binary(), final_uri: URI.t(), headers: headers(), runtime_ms: timeout(), status: non_neg_integer(), uri_sequence: [URI.t(), ...] }
Fields on a response:
:body
: the response body. For HTML documents, this will always be aString.t()
, but for binary files like images and videos, it will be non-Unicode binary data.:headers
: a map from response header names (all lowercase, like"content-encoding"
) to the values associated with that header. This is structured as a map, the way theReq
library does, to make it clear that servers may legitimately send multiple values for the same header name.:status
: the HTTP status code returned by the final URL in the chain of redirects, like200
or404
.:final_uri
: the final URL in the chain of redirects, as aURI
.:uri_sequence
: the complete chain of URLs that were visited (length 1 if there were no redirects), as a list ofURI
s. The first element will always be URL that was passed toBrowseyHttp.get/2
, and the last will always be the:final_uri
.:runtime_ms
: the number of milliseconds the request took to complete, including all redirects.
Functions
Converts our headers from a map to a list of 2-tuples in the format used by Finch or HTTPoison.
Examples
iex> BrowseyHttp.Response.headers_to_proplist(%{body: "...", headers: %{"content-type" => ["text/html"]}})
[{"content-type", "text/html"}]
iex> BrowseyHttp.Response.headers_to_proplist(%{body: "...", headers: %{"content-encoding" => ["gzip", "br"]}})
[{"content-encoding", "gzip"}, {"content-encoding", "br"}]
@spec html?(has_headers_and_body()) :: boolean()
True if the response appears to be HTML, either based on its headers or its body content.
The original URL passed to BrowseyHttp.get/2
, before any redirects.
Converts headers in the 2-tuple format used by Finch or HTTPoison to a map used by BrowseyHttp.get/2
.
Examples
iex> BrowseyHttp.Response.proplist_to_headers([{"Content-Type", "text/html"}])
%{"content-type" => ["text/html"]}
iex> BrowseyHttp.Response.proplist_to_headers([{"content-encoding", "gzip"}, {"content-encoding", "br"}])
%{"content-encoding" => ["gzip", "br"]}
@spec status_name(non_neg_integer()) :: String.t()
The human readable title for an HTTP error status code.