Module cowmachine_req

Request functions for cowmachine.

Copyright © 2016-2019 Marc Worrell

Authors: Marc Worrell (marc@worrell.nl).

Description

Request functions for cowmachine

Data Types

context()

context() = context_map() | tuple()

context_map()

context_map() = #{cowreq := cowboy_req:req(), cowenv := cowboy_middleware:env(), any() => any()}

halt()

halt() = {error, term()} | {halt, 200..599}

media_type()

media_type() = binary() | {binary(), binary(), [{binary(), binary()}]} | {binary(), binary()} | {binary(), [{binary(), binary()}]}

outputfun()

outputfun() = fun((iodata(), IsFinal::boolean(), context()) -> context())

parts()

parts() = all | {ranges(), Size::non_neg_integer(), Boundary::binary(), ContentType::binary()}

ranges()

ranges() = [{Offset::non_neg_integer(), Length::non_neg_integer()}]

resp_body()

resp_body() = iodata() | {device, Size::non_neg_integer(), file:io_device()} | {device, file:io_device()} | {file, Size::non_neg_integer(), file:filename_all()} | {file, file:filename_all()} | {stream, {streamdata(), streamfun()}} | {stream, Size::non_neg_integer(), {streamdata(), streamfun()}} | {stream, streamfun()} | {stream, Size::non_neg_integer(), streamfun()} | {writer, writerfun()} | undefined

streamdata()

streamdata() = iodata() | {file, non_neg_integer(), file:filename_all()} | {file, file:filename_all()}

streamfun()

streamfun() = fun((parts(), context()) -> {streamdata(), streamfun_next()}) | fun((context()) -> {streamdata(), streamfun_next()}) | fun(() -> {streamdata(), streamfun_next()}) | done

streamfun_next()

streamfun_next() = fun((context()) -> {streamdata(), streamfun_next()}) | fun(() -> {streamdata(), streamfun_next()}) | done

writerfun()

writerfun() = fun((outputfun(), context()) -> context())

Function Index

base_uri/1Return the base uri of the request.
controller/1Return the current cowmachine controller.
controller_options/1Return the current cowmachine controller options.
disp_path/1Return the dispatch path of the request.
encode_content/2Encode the content according to the selected content encoding.
env/1Fetch the cowboy middleware env from the context.
get_cookie_value/2Fetch the value of a cookie.
get_metadata/2
get_req_header/2Fetch a request header, the header must be a lowercase binary.
get_req_headers/1Fetch all request headers.
get_resp_cookies/1Fetch all response cookies.
get_resp_header/2Fetch the response header, undefined if not set.
get_resp_headers/1Fetch all response headers.
has_req_body/1Check if the request has a body.
has_resp_body/1Check if a response body has been set.
host/1Return the http host.
init_context/3Initialize the context with the Req and Env.
init_env/2Set some intial metadata in the cowboy req.
is_proxy/1Check if the request is forwarded by a proxy.
is_range_ok/1Fetch the 'is_range_ok' flag.
is_ssl/1Check if the connection is secure (SSL).
method/1Return the request Method.
path/1Return the undecoded request path as-is.
path_info/1Fetch all bindings from the dispatcher.
peer/1Return the peer of this request, take x-forwarded-for into account if the peer is an ip4 LAN address.
peer_ip/1Return the peer of this request, take x-forwarded-for into account if the peer is an ip4 LAN address.
port/1Return the http port.
qs/1Return the undecoded query string, <<>> when no query string.
raw_path/1Return the undecoded request path as-is, including the query string.
remove_resp_header/2Remove the response header from the list for response headers.
req/1Fetch the cowboy request from the context.
req_body/1Fetch the request body as a single binary.
req_body/2
req_cookie/1Fetch all cookies.
req_qs/1Return the decoded query string, [] when no query string.
resp_body/1Return the response body, this must be converted to a response body that Cowboy can handle.
resp_chosen_charset/1Get the chosen charset.
resp_content_encoding/1Get the content encoding.
resp_content_type/1Fetch the content type of the response.
resp_redirect/1Return the 'redirect' flag, used during POST processing to check if a 303 should be returned.
resp_transfer_encoding/1Get the transfer encoding.
response_code/1Fetch the preliminary HTTP response code for the request.
scheme/1Return the scheme used (https or http).
set_disp_path/2Set the dispatch path of the request.
set_env/2Update the cowboy middleware env in the context.
set_metadata/3
set_range_ok/2Set the 'is_range_ok' flag.
set_req/2Update the cowboy request in the context.
set_resp_body/2Set the response body, this must be converted to a response body that Cowboy can handle.
set_resp_chosen_charset/2Set the chosen charset.
set_resp_content_encoding/2Set the content encoding.
set_resp_content_type/2Set the content type of the response.
set_resp_cookie/4Add a cookie to the response cookies.
set_resp_header/3Add a response header, replacing an existing header with the same name.
set_resp_headers/2Set multiple response headers.
set_resp_redirect/2Set the 'redirect' flag, used during POST processing to check if a 303 should be returned.
set_resp_transfer_encoding/2Set the transfer encoding.
set_response_code/2Set the preliminary HTTP response code for the request.
site/1Return the cowmachine site.
stream_req_body/2
version/1Return the http version as a tuple {minor,major}.

Function Details

base_uri/1

base_uri(Context::context()) -> binary()

Return the base uri of the request.

controller/1

controller(Context::context()) -> module()

Return the current cowmachine controller

controller_options/1

controller_options(Context::context()) -> list()

Return the current cowmachine controller options

disp_path/1

disp_path(Context::context()) -> binary() | undefined

Return the dispatch path of the request.

encode_content/2

encode_content(Content::iodata(), Context::context()) -> iolist()

Encode the content according to the selected content encoding

env/1

env(Context::context()) -> cowboy_middleware:env()

Fetch the cowboy middleware env from the context.

get_cookie_value/2

get_cookie_value(Name::binary(), Context::context()) -> binary() | undefined

Fetch the value of a cookie.

get_metadata/2

get_metadata(Key::atom(), Context::context()) -> term() | undefined

get_req_header/2

get_req_header(H::binary(), Context::context()) -> binary() | undefined

Fetch a request header, the header must be a lowercase binary.

get_req_headers/1

get_req_headers(Context::context()) -> #{binary() => binary()}

Fetch all request headers.

get_resp_cookies/1

get_resp_cookies(Context::context()) -> [{binary(), binary()}]

Fetch all response cookies.

get_resp_header/2

get_resp_header(Header::binary(), Context::context()) -> binary() | undefined

Fetch the response header, undefined if not set.

get_resp_headers/1

get_resp_headers(Context::context()) -> map()

Fetch all response headers.

has_req_body/1

has_req_body(Context::context()) -> boolean()

Check if the request has a body

has_resp_body/1

has_resp_body(Context::context()) -> boolean()

Check if a response body has been set.

host/1

host(Context::context()) -> binary()

Return the http host

init_context/3

init_context(Req::cowboy_req:req(), Env::cowboy_middleware:env(), M::undefined | map() | tuple()) -> context()

Initialize the context with the Req and Env

init_env/2

init_env(Req::cowboy_req:req(), Env::cowboy_middleware:env()) -> cowboy_middleware:env()

Set some intial metadata in the cowboy req

is_proxy/1

is_proxy(Context::context()) -> boolean()

Check if the request is forwarded by a proxy

is_range_ok/1

is_range_ok(Context::context()) -> boolean()

Fetch the 'is_range_ok' flag.

is_ssl/1

is_ssl(Context::context()) -> boolean()

Check if the connection is secure (SSL)

method/1

method(Context::context()) -> binary()

Return the request Method

path/1

path(Context::context()) -> binary()

Return the undecoded request path as-is

path_info/1

path_info(Context::context()) -> cowboy_router:bindings()

Fetch all bindings from the dispatcher.

peer/1

peer(Context::context()) -> binary()

Return the peer of this request, take x-forwarded-for into account if the peer is an ip4 LAN address

peer_ip/1

peer_ip(Context::context()) -> tuple()

Return the peer of this request, take x-forwarded-for into account if the peer is an ip4 LAN address

port/1

port(Context::context()) -> integer()

Return the http port

qs/1

qs(Context::context()) -> binary()

Return the undecoded query string, <<>> when no query string.

raw_path/1

raw_path(Context::context()) -> binary()

Return the undecoded request path as-is, including the query string

remove_resp_header/2

remove_resp_header(Header::binary(), Context::context()) -> context()

Remove the response header from the list for response headers.

req/1

req(Context::context()) -> cowboy_req:req()

Fetch the cowboy request from the context.

req_body/1

req_body(Context::context()) -> {binary() | undefined, context()}

Fetch the request body as a single binary. Per default we don't receive more than ~128K bytes.

req_body/2

req_body(MaxLength::non_neg_integer(), Context::context()) -> {binary() | undefined, context()}

req_cookie/1

req_cookie(Context::context()) -> list()

Fetch all cookies.

req_qs/1

req_qs(Context::context()) -> [{binary(), binary()}]

Return the decoded query string, [] when no query string.

resp_body/1

resp_body(Context::context()) -> resp_body()

Return the response body, this must be converted to a response body that Cowboy can handle.

resp_chosen_charset/1

resp_chosen_charset(Context::context()) -> binary() | undefined

Get the chosen charset.

resp_content_encoding/1

resp_content_encoding(Context::context()) -> binary()

Get the content encoding.

resp_content_type/1

resp_content_type(Context::context()) -> cow_http_hd:media_type()

Fetch the content type of the response

resp_redirect/1

resp_redirect(Context::context()) -> boolean()

Return the 'redirect' flag, used during POST processing to check if a 303 should be returned.

resp_transfer_encoding/1

resp_transfer_encoding(Context::context()) -> {binary(), function()} | undefined

Get the transfer encoding.

response_code/1

response_code(Context::context()) -> integer()

Fetch the preliminary HTTP response code for the request. This can be changed.

scheme/1

scheme(Context::context()) -> http | https

Return the scheme used (https or http)

set_disp_path/2

set_disp_path(Path::binary(), Context::context()) -> context()

Set the dispatch path of the request.

set_env/2

set_env(Env::cowboy_middleware:env(), Context::context()) -> context()

Update the cowboy middleware env in the context.

set_metadata/3

set_metadata(Key::atom(), Value::term(), Context::context()) -> context()

set_range_ok/2

set_range_ok(IsRangeOk::boolean(), Context::context()) -> context()

Set the 'is_range_ok' flag.

set_req/2

set_req(Req::cowboy_req:req(), Context::context()) -> context()

Update the cowboy request in the context.

set_resp_body/2

set_resp_body(RespBody::resp_body(), Context::context()) -> context()

Set the response body, this must be converted to a response body that Cowboy can handle.

set_resp_chosen_charset/2

set_resp_chosen_charset(CharSet::binary() | undefined, Context::context()) -> context()

Set the chosen charset.

set_resp_content_encoding/2

set_resp_content_encoding(Enc::binary(), Context::context()) -> context()

Set the content encoding

set_resp_content_type/2

set_resp_content_type(CT::cow_http_hd:media_type() | binary(), Context::context()) -> context()

Set the content type of the response

set_resp_cookie/4

set_resp_cookie(Key::binary(), Value::binary(), Options::list(), Context::context()) -> context()

Add a cookie to the response cookies

set_resp_header/3

set_resp_header(Header::binary(), Rs::binary() | [binary()] | string(), Context::context()) -> context()

Add a response header, replacing an existing header with the same name. The header must be a lowercased binary. If the value is a list of binaries then they are joined with a comma as separator.

set_resp_headers/2

set_resp_headers(Hs::[{binary(), binary()}], Context::context()) -> context()

Set multiple response headers.

set_resp_redirect/2

set_resp_redirect(Location::boolean() | binary(), Context::context()) -> context()

Set the 'redirect' flag, used during POST processing to check if a 303 should be returned.

set_resp_transfer_encoding/2

set_resp_transfer_encoding(Enc::{binary(), function()}, Context::context()) -> context()

Set the transfer encoding

set_response_code/2

set_response_code(Code::integer(), Context::context()) -> context()

Set the preliminary HTTP response code for the request. This can be changed.

site/1

site(Context::context()) -> atom()

Return the cowmachine site.

stream_req_body/2

stream_req_body(ChunkSize::non_neg_integer(), Context::context()) -> {ok | more, binary(), context()}

version/1

version(Context::context()) -> {Major::integer(), Minor::integer()}

Return the http version as a tuple {minor,major}.


Generated by EDoc