antikythera v0.4.0 Antikythera.Conn View Source

Definition of Antikythera.Conn struct, which represents a client-server connection.

This module also defines many functions to work with Antikythera.Conn.

Link to this section Summary

Functions

Type-aware getter for assigns.

Type-aware setter for assigns.

Type-aware getter for before_send.

Type-aware setter for before_send.

Type-aware getter for context.

Type-aware setter for context.

Gets a flash message stored in the given Antikythera.Conn.t/0.

Returns a request cookie specified by name.

Returns all request cookies.

Returns a JSON response.

Creates a new instance of Antikythera.Conn by using the given dict.

A variant of new/1 which returns t or raise if validation fails.

Put cache-control response header for responses that must not be cached.

Stores the flash message into the current Antikythera.Conn.t/0.

Adds a set-cookie response header to the given Antikythera.Conn.t.

Tells the client to delete an existing cookie specified by name.

Returns an HTTP response that make the client redirect to the specified url.

Renders a HAML template file and returns the dynamic content as an HTML response.

Type-aware getter for request.

Type-aware setter for request.

Type-aware getter for resp_body.

Type-aware setter for resp_body.

Type-aware getter for resp_cookies.

Type-aware setter for resp_cookies.

Type-aware getter for resp_headers.

Type-aware setter for resp_headers.

Sends a file which resides in priv/ directory as a response.

Type-aware getter for status.

Type-aware setter for status.

Updates an existing instance of Antikythera.Conn with the given dict. The values in the dict are validated by each field's valid?/1 function. Returns {:ok, valid_struct} or {:error, reason}.

A variant of update/2 which returns t or raise if validation fails. In other words, update/2 followed by Croma.Result.get!/1.

Checks if the given value belongs to t/0 or not.

Link to this section Types

Specs

t() :: %Antikythera.Conn{
  assigns: Antikythera.Conn.Assigns.t(),
  before_send: Antikythera.Conn.BeforeSend.t(),
  context: Antikythera.Context.t(),
  request: Antikythera.Request.t(),
  resp_body: Antikythera.Http.RawBody.t(),
  resp_cookies: Antikythera.Http.SetCookiesMap.t(),
  resp_headers: Antikythera.Http.Headers.t(),
  status: Croma.TypeGen.Nilable.Antikythera.Http.Status.Int.t()
}

Link to this section Functions

Link to this function

assign(conn, key, value)

View Source

Specs

assign(Antikythera.Conn.t(), atom(), any()) :: t()

Specs

assigns(t()) :: Antikythera.Conn.Assigns.t()

Type-aware getter for assigns.

Specs

assigns(t(), Antikythera.Conn.Assigns.t()) :: t()

Type-aware setter for assigns.

Specs

before_send(t()) :: Antikythera.Conn.BeforeSend.t()

Type-aware getter for before_send.

Specs

before_send(t(), Antikythera.Conn.BeforeSend.t()) :: t()

Type-aware setter for before_send.

Specs

clear_session(Antikythera.Conn.t()) :: t()

Specs

context(t()) :: Antikythera.Context.t()

Type-aware getter for context.

Specs

context(t(), Antikythera.Context.t()) :: t()

Type-aware setter for context.

Link to this function

delete_session(conn, key)

View Source

Specs

delete_session(Antikythera.Conn.t(), String.t()) :: t()

Specs

destroy_session(Antikythera.Conn.t()) :: t()

Specs

get_flash(Antikythera.Conn.t(), String.t()) :: nil | String.t()

Gets a flash message stored in the given Antikythera.Conn.t/0.

Link to this function

get_req_cookie(conn, name)

View Source

Specs

get_req_cookie(t(), String.t()) :: nil | String.t()

Returns a request cookie specified by name.

Specs

Returns all request cookies.

Link to this function

get_req_header(arg0, key)

View Source

Specs

get_req_header(Antikythera.Conn.t(), String.t()) :: nil | String.t()
Link to this function

get_req_query(arg0, key)

View Source

Specs

get_req_query(Antikythera.Conn.t(), String.t()) :: nil | String.t()

Specs

get_session(Antikythera.Conn.t(), String.t()) :: any()
Link to this function

json(conn, status, body)

View Source

Specs

json(
  Antikythera.Conn.t(),
  Antikythera.Http.Status.t(),
  %{required(atom() | String.t()) => any()} | [any()]
) :: t()

Returns a JSON response.

Specs

new(term()) :: Croma.Result.t(t())

Creates a new instance of Antikythera.Conn by using the given dict.

Returns {:ok, valid_struct} or {:error, reason}.

The values in the dict are validated by each field's valid?/1 function. If the value was invalid, it will be passed to new/1 of the field

For missing fields, followings will be tried:

  • default/0 of each field type
  • new/1 of each field type, with empty map as input

Specs

new!(term()) :: t()

A variant of new/1 which returns t or raise if validation fails.

In other words, new/1 followed by Croma.Result.get!/1.

Specs

no_cache(t()) :: t()

Put cache-control response header for responses that must not be cached.

The actual header value to be set is: "private, no-cache, no-store, max-age=0".

Link to this function

put_flash(conn, key, value)

View Source

Specs

put_flash(Antikythera.Conn.t(), String.t(), String.t()) :: t()

Stores the flash message into the current Antikythera.Conn.t/0.

Link to this function

put_resp_body(conn, body)

View Source

Specs

put_resp_body(t(), String.t()) :: t()
Link to this function

put_resp_cookie(conn, name, value, opts0 \\ %{})

View Source

Specs

Adds a set-cookie response header to the given Antikythera.Conn.t.

path directive of set-cookie header is automatically filled with "/" if not explicitly given. Also secure directive is filled by default in the cloud environments (assuming that it's serving with HTTPS).

Note that response cookies are stored separately from the other response headers, as cookies require special treatment according to the HTTP specs.

Link to this function

put_resp_header(conn, key, value)

View Source

Specs

put_resp_header(Antikythera.Conn.t(), String.t(), String.t()) :: t()
Link to this function

put_resp_headers(conn, headers)

View Source

Specs

put_resp_headers(Antikythera.Conn.t(), %{required(String.t()) => String.t()}) ::
  t()
Link to this function

put_session(conn, key, value)

View Source

Specs

put_session(Antikythera.Conn.t(), String.t(), any()) :: t()
Link to this function

put_status(conn, status)

View Source

Specs

put_status(t(), Antikythera.Http.Status.t()) :: t()
Link to this function

redirect(conn, url, status \\ 302)

View Source

Specs

redirect(t(), String.t(), Antikythera.Http.Status.t()) :: t()

Returns an HTTP response that make the client redirect to the specified url.

Link to this function

register_before_send(conn, callback)

View Source

Specs

register_before_send(Antikythera.Conn.t(), (t() -> t())) :: t()
Link to this function

render(conn, status, template_name, render_params, opts \\ [layout: :application])

View Source

Specs

Renders a HAML template file and returns the dynamic content as an HTML response.

Specs

renew_session(Antikythera.Conn.t()) :: t()

Specs

request(t()) :: Antikythera.Request.t()

Type-aware getter for request.

Specs

request(t(), Antikythera.Request.t()) :: t()

Type-aware setter for request.

Specs

resp_body(t()) :: Antikythera.Http.RawBody.t()

Type-aware getter for resp_body.

Specs

resp_body(t(), Antikythera.Http.RawBody.t()) :: t()

Type-aware setter for resp_body.

Specs

resp_cookies(t()) :: Antikythera.Http.SetCookiesMap.t()

Type-aware getter for resp_cookies.

Specs

resp_cookies(t(), Antikythera.Http.SetCookiesMap.t()) :: t()

Type-aware setter for resp_cookies.

Specs

resp_headers(t()) :: Antikythera.Http.Headers.t()

Type-aware getter for resp_headers.

Specs

resp_headers(t(), Antikythera.Http.Headers.t()) :: t()

Type-aware setter for resp_headers.

Link to this function

send_priv_file(conn, status, path)

View Source

Specs

send_priv_file(Antikythera.Conn.t(), Antikythera.Http.Status.t(), Path.t()) ::
  t()

Sends a file which resides in priv/ directory as a response.

path must be a file path relative to the priv/ directory. content-type header is inferred from the file's extension.

Don't use this function for sending large files; you should use CDN for large files (see Antikythera.Asset). Also, if all you need to do is just to return a file (i.e. you don't need any authentication), you should not use this function; just placing the file under priv/static/ directory should suffice.

Specs

status(t()) :: Croma.TypeGen.Nilable.Antikythera.Http.Status.Int.t()

Type-aware getter for status.

Specs

status(t(), Croma.TypeGen.Nilable.Antikythera.Http.Status.Int.t()) :: t()

Type-aware setter for status.

Specs

update(t(), Dict.t()) :: Croma.Result.t(t())

Updates an existing instance of Antikythera.Conn with the given dict. The values in the dict are validated by each field's valid?/1 function. Returns {:ok, valid_struct} or {:error, reason}.

Specs

update!(t(), Dict.t()) :: t()

A variant of update/2 which returns t or raise if validation fails. In other words, update/2 followed by Croma.Result.get!/1.

Specs

valid?(term()) :: boolean()

Checks if the given value belongs to t/0 or not.