crawlie v1.0.0 Crawlie.Response

Defines the struct representing a page retrieved by the http client.

Summary

Types

t()

The Crawlie.Response struct type

Functions

Retrieves the (downcased) content type of the response

Retrieves the (downcased) content type of the response, just the “type/subtype” part, with no additional parameters, if there are any in the Content-Type header value

Returns the string representation of the uri contained in the Crawlie.Response struct

Types

t()
t() :: %Crawlie.Response{body: binary, content_type: String.t | nil, content_type_simple: String.t | nil, headers: [{String.t, String.t}], status_code: integer, uri: URI.t}

The Crawlie.Response struct type.

Functions

content_type(response)
content_type(Crawlie.Response.t) :: String.t | nil

Retrieves the (downcased) content type of the response.

Deprecated, you can use response.content_type directly

Example

iex> alias Crawlie.Response
iex> url = "https://foo.bar/"
iex> headers = [{"Content-Type", "text/html; charset=UTF-8"}]
iex> response = Response.new(url, 200, headers, "<html />")
iex> Response.content_type(response)
"text/html; charset=utf-8"
iex> Response.content_type(response) == response.content_type
true
content_type_simple(response)
content_type_simple(Crawlie.Response.t) :: String.t | nil

Retrieves the (downcased) content type of the response, just the “type/subtype” part, with no additional parameters, if there are any in the Content-Type header value.

Deprecated, you can use response.content_type_simple directly

Example

iex> alias Crawlie.Response
iex> url = "https://foo.bar/"
iex> headers = [{"Content-Type", "text/html; charset=UTF-8"}]
iex> response = Response.new(url, 200, headers, "<html />")
iex> Response.content_type_simple(response)
"text/html"
iex> Response.content_type_simple(response) == response.content_type_simple
true
new(url, status_code, headers, body)
new(String.t | URI.t, integer, [{String.t, String.t}], binary) :: Crawlie.Response.t

Constructs the Crawlie.Response struct.

Example

iex> alias Crawlie.Response
iex> url = "https://foo.bar/"
iex> headers = [{"Content-Type", "text/plain"}]
iex> response = Response.new(url, 200, headers, "body")
iex> response.body
"body"
iex> response.status_code
200
url(this)

Returns the string representation of the uri contained in the Crawlie.Response struct.