Skip to content

Instantly share code, notes, and snippets.

@essen essen/ast1.erl
Created Oct 14, 2016

Embed
What would you like to do?
[{h1,<<"cowboy_req:method(3)">>},
{h2,<<"Name">>},
{p,[<<"cowboy_req:method - HTTP method">>]},
{h2,<<"Description">>},
{listing,#{language => <<"erlang">>},
<<"method(Req :: cowboy_req:req()) -> Method :: binary()">>},
{p,[<<"Return the request's HTTP method.">>]},
{p,[<<"The method can also be obtained using pattern matching:">>]},
{listing,#{language => <<"erlang">>},<<"#{method := Method} = Req.">>},
{h2,<<"Arguments">>},
{ll,[{li,<<"Req">>,[{p,[<<"The Req object.">>]}]}]},
{h2,<<"Return value">>},
{p,[<<"The request's HTTP method is returned as a binary string. While methods are case sensitive, standard methods are always uppercase.">>]},
{h2,<<"Changelog">>},
{ul,[{li,[{p,[<<>>,
{em,<<"2.0">>},
<<": Only the method is returned, it is no longer wrapped in a tuple.">>]}]},
{li,[{p,[<<>>,{em,<<"1.0">>},<<": Function introduced.">>]}]}]},
{h2,<<"Examples">>},
{listing,#{language => <<"erlang">>,
title => <<"Ensure the request's method is GET">>},
<<"<<\"GET\">> = cowboy_req:method(Req).">>},
{listing,#{language => <<"erlang">>,title => <<"Allow methods from list">>},
<<"init(Req, State) ->\n case lists:member(cowboy_req:method(Req), [<<\"GET\">>, <<\"POST\">>]) of\n true -> handle(Req, State);\n false -> method_not_allowed(Req, State)\n end.">>},
{h2,<<"See also">>},
{p,[<<>>,{link,<<"man:cowboy_req(3)">>,<<"cowboy_req(3)">>}]}]
[{h1,<<"cowboy_req(3)">>},
{h2,<<"Name">>},
{p,[<<"cowboy_req - HTTP request and response">>]},
{h2,<<"Description">>},
{p,[<<"The module ">>,
{mono,<<"cowboy_req">>},
<<" provides functions to access, manipulate and respond to requests.">>]},
{p,[<<"There are four types of functions in this module. They can be differentiated by their name and their return type:">>]},
{table,#{num_cols => 3,others => [<<"options=\"header\"">>]},
[{row,[{cell,[{p,[<<"Type">>]}]},
{cell,[{p,[<<"Name pattern">>]}]},
{cell,[{p,[<<"Return type">>]}]}]},
{row,[{cell,[{p,[<<"access">>]}]},
{cell,[{p,[<<"no verb, parse_*, match_*">>]}]},
{cell,[{p,[<<>>,{mono,<<"Value">>}]}]}]},
{row,[{cell,[{p,[<<"question">>]}]},
{cell,[{p,[<<"has_*">>]}]},
{cell,[{p,[<<>>,{mono,<<"boolean()">>}]}]}]},
{row,[{cell,[{p,[<<"modification">>]}]},
{cell,[{p,[<<"set_*">>]}]},
{cell,[{p,[<<>>,{mono,<<"Req">>}]}]}]},
{row,[{cell,[{p,[<<"action">>]}]},
{cell,[{p,[<<"any other verb">>]}]},
{cell,[{p,[<<>>,
{mono,<<"ok \\| {Result, Value, Req}">>}]}]}]}]},
{p,[<<"Any ">>,
{mono,<<"Req">>},
<<" returned must be used in place of the one passed as argument. Functions that perform an action in particular write state in the Req object to make sure you are using the function correctly. For example, it's only possible to send one response, and to read the body once.">>]},
{h2,<<"Exports">>},
{p,[<<"Raw request:">>]},
{ul,[{li,[{p,[<<>>,
{link,<<"man:cowboy_req:method(3)">>,
<<"cowboy_req:method(3)">>},
<<" - HTTP method">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:version(3)">>,
<<"cowboy_req:version(3)">>},
<<" - HTTP version">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:scheme(3)">>,
<<"cowboy_req:scheme(3)">>},
<<" - URI scheme">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:host(3)">>,<<"cowboy_req:host(3)">>},
<<" - URI host name">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:port(3)">>,<<"cowboy_req:port(3)">>},
<<" - URI port number">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:path(3)">>,<<"cowboy_req:path(3)">>},
<<" - URI path">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:qs(3)">>,<<"cowboy_req:qs(3)">>},
<<" - URI query string">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:uri(3)">>,<<"cowboy_req:uri(3)">>},
<<" - Reconstructed URI">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:header(3)">>,
<<"cowboy_req:header(3)">>},
<<" - Raw HTTP header value">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:headers(3)">>,
<<"cowboy_req:headers(3)">>},
<<" - Raw HTTP headers">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:peer(3)">>,<<"cowboy_req:peer(3)">>},
<<" - Peer address and port">>]}]}]},
{p,[<<"Processed request:">>]},
{ul,[{li,[{p,[<<>>,
{link,<<"man:cowboy_req:parse_qs(3)">>,
<<"cowboy_req:parse_qs(3)">>},
<<" - Parse the query string">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:match_qs(3)">>,
<<"cowboy_req:match_qs(3)">>},
<<" - Match the query string against constraints">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:parse_header(3)">>,
<<"cowboy_req:parse_header(3)">>},
<<" - Parse the given HTTP header">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:parse_cookies(3)">>,
<<"cowboy_req:parse_cookies(3)">>},
<<" - Parse cookie headers">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:match_cookies(3)">>,
<<"cowboy_req:match_cookies(3)">>},
<<" - Match cookies against constraints">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:binding(3)">>,
<<"cowboy_req:binding(3)">>},
<<" - Access a value bound from the route">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:bindings(3)">>,
<<"cowboy_req:bindings(3)">>},
<<" - Access all values bound from the route">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:host_info(3)">>,
<<"cowboy_req:host_info(3)">>},
<<" - Access the route's heading host segments">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:path_info(3)">>,
<<"cowboy_req:path_info(3)">>},
<<" - Access the route's trailing path segments">>]}]}]},
{p,[<<"Request body:">>]},
{ul,[{li,[{p,[<<>>,
{link,<<"man:cowboy_req:has_body(3)">>,
<<"cowboy_req:has_body(3)">>},
<<" - Is there a request body?">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:body_length(3)">>,
<<"cowboy_req:body_length(3)">>},
<<" - Body length">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:read_body(3)">>,
<<"cowboy_req:read_body(3)">>},
<<" - Read the request body">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:read_urlencoded_body(3)">>,
<<"cowboy_req:read_urlencoded_body(3)">>},
<<" - Read and parse a urlencoded request body">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:read_part(3)">>,
<<"cowboy_req:read_part(3)">>},
<<" - Read the next part of a multipart body">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:read_part_body(3)">>,
<<"cowboy_req:read_part_body(3)">>},
<<" - Read the current part's body in a multipart body">>]}]}]},
{p,[<<"Response:">>]},
{ul,[{li,[{p,[<<>>,
{link,<<"man:cowboy_req:set_resp_cookie(3)">>,
<<"cowboy_req:set_resp_cookie(3)">>},
<<" - Set a cookie">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:set_resp_header(3)">>,
<<"cowboy_req:set_resp_header(3)">>},
<<" - Set a response header">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:has_resp_header(3)">>,
<<"cowboy_req:has_resp_header(3)">>},
<<" - Is the given response header set?">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:delete_resp_header(3)">>,
<<"cowboy_req:delete_resp_header(3)">>},
<<" - Delete a response header">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:set_resp_body(3)">>,
<<"cowboy_req:set_resp_body(3)">>},
<<" - Set the response body">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:has_resp_body(3)">>,
<<"cowboy_req:has_resp_body(3)">>},
<<" - Is there a response body?">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:reply(3)">>,<<"cowboy_req:reply(3)">>},
<<" - Send the response">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:stream_reply(3)">>,
<<"cowboy_req:stream_reply(3)">>},
<<" - Send the response and stream its body">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:stream_body(3)">>,
<<"cowboy_req:stream_body(3)">>},
<<" - Send a chunk of the response body">>]}]},
{li,[{p,[<<>>,
{link,<<"man:cowboy_req:push(3)">>,<<"cowboy_req:push(3)">>},
<<" - Push a resource to the client">>]}]}]},
{h2,<<"Types">>},
{h3,<<"push_opts()">>},
{listing,#{language => <<"erlang">>},
<<"push_opts() :: #{\n method => binary(), %% case sensitive\n scheme => binary(), %% lowercase; case insensitive\n host => binary(), %% lowercase; case insensitive\n port => inet:port_number(),\n qs => binary() %% case sensitive\n}">>},
{p,[<<"Push options.">>]},
{p,[<<"By default, Cowboy will use the GET method, an empty query string, and take the scheme, host and port directly from the current request's URI.">>]},
{h3,<<"read_body_opts()">>},
{listing,#{language => <<"erlang">>},
<<"read_body_opts() :: #{\n length => non_neg_integer(),\n period => non_neg_integer(),\n timeout => timeout()\n}">>},
{p,[<<"Body reading options.">>]},
{p,[<<"The defaults are function-specific.">>]},
{h3,<<"req()">>},
{listing,#{language => <<"erlang">>},
<<"req() :: #{\n method := binary(), %% case sensitive\n version := cowboy:http_version() | atom(),\n scheme := binary(), %% lowercase; case insensitive\n host := binary(), %% lowercase; case insensitive\n port := inet:port_number(),\n path := binary(), %% case sensitive\n qs := binary(), %% case sensitive\n headers := cowboy:http_headers(),\n peer := {inet:ip_address(), inet:port_number()}\n}">>},
{p,[<<"The Req object.">>]},
{p,[<<"Contains information about the request and response. While some fields are publicly documented, others aren't and shouldn't be used.">>]},
{p,[<<"You may add custom fields if required. Make sure to namespace them by prepending an underscore and the name of your application:">>]},
{listing,#{language => <<"erlang">>,title => <<"Setting a custom field">>},
<<"Req#{_myapp_auth_method => pubkey}.">>},
{h3,<<"resp_body()">>},
{listing,#{language => <<"erlang">>},
<<"resp_body() :: iodata()\n | {sendfile, Offset, Length, Filename}\n\nOffset :: non_neg_integer()\nLength :: pos_integer()\nFilename :: file:name_all()">>},
{p,[<<"Response body.">>]},
{p,[<<"It can take two forms: the actual data to be sent or a tuple indicating which file to send.">>]},
{p,[<<"When sending data directly, the type is either a binary or an iolist. Iolists are an efficient way to build output. Instead of concatenating strings or binaries, you can simply build a list containing the fragments you want to send in the order they should be sent:">>]},
{listing,#{language => <<"erlang">>,title => <<"Example iolists usage">>},
<<"1> RespBody = [\"Hello \", [<<\"world\">>, $!]].\n[\"Hello \",[<<\"world\">>,33]]\n2> io:format(\"~s~n\", [RespBody]).\nHello world!">>},
{p,[<<"When using the sendfile tuple, the ">>,
{mono,<<"Length">>},
<<" value is mandatory and must be higher than 0. It is sent with the response in the content-length header.">>]},
{comment,<<" @todo Make sure we have a test with an empty file...">>},
{comment,<<" @todo cowboy_static should probably NOT return a sendfile tuple if size is 0.">>},
{comment,<<"%% While sendfile allows a Len of 0 that means \"everything past Offset\",">>},
{comment,<<"%% Cowboy expects the real length as it is used as metadata.">>},
{comment,<<"%% @todo We should probably explicitly reject it.">>},
{h2,<<"See also">>},
{p,[<<>>,{link,<<"man:cowboy(7)">>,<<"cowboy(7)">>}]},
{comment,<<"== Request related exports">>},
{comment,<<>>},
{comment,<<"=== binding(Name, Req) -> binding(Name, Req, undefined)">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:binding/3`.">>},
{comment,<<>>},
{comment,<<"=== binding(Name, Req, Default) -> Value">>},
{comment,<<>>},
{comment,<<"Name = atom():: Binding name.">>},
{comment,<<"Default = any():: Default value.">>},
{comment,<<"Value = any() | Default:: Binding value.">>},
{comment,<<>>},
{comment,<<"Return the value for the given binding.">>},
{comment,<<>>},
{comment,<<"By default the value is a binary, however constraints may change">>},
{comment,<<"the type of this value (for example automatically converting">>},
{comment,<<"numbers to integer).">>},
{comment,<<>>},
{comment,<<"=== bindings(Req) -> [{Name, Value}]">>},
{comment,<<>>},
{comment,<<"Name = atom():: Binding name.">>},
{comment,<<"Value = any():: Binding value.">>},
{comment,<<>>},
{comment,<<"Return all bindings.">>},
{comment,<<>>},
{comment,<<"By default the value is a binary, however constraints may change">>},
{comment,<<"the type of this value (for example automatically converting">>},
{comment,<<"numbers to integer).">>},
{comment,<<>>},
{comment,<<"=== header(Name, Req) -> header(Name, Req, undefined)">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:header/3`.">>},
{comment,<<>>},
{comment,<<"=== header(Name, Req, Default) -> Value">>},
{comment,<<>>},
{comment,<<"Name = binary():: Request header name.">>},
{comment,<<"Default = any():: Default value.">>},
{comment,<<"Value = binary() | Default:: Request header value.">>},
{comment,<<>>},
{comment,<<"Return the value for the given header.">>},
{comment,<<>>},
{comment,<<"While header names are case insensitive, this function expects">>},
{comment,<<"the name to be a lowercase binary.">>},
{comment,<<>>},
{comment,<<"=== headers(Req) -> Headers">>},
{comment,<<>>},
{comment,<<"Headers = cowboy:http_headers():: Request headers.">>},
{comment,<<>>},
{comment,<<"Return all headers.">>},
{comment,<<>>},
{comment,<<"=== host(Req) -> Host">>},
{comment,<<>>},
{comment,<<"Host = binary():: Requested host.">>},
{comment,<<>>},
{comment,<<"Return the requested host.">>},
{comment,<<>>},
{comment,<<"=== host_info(Req) -> HostInfo">>},
{comment,<<>>},
{comment,<<"HostInfo = cowboy_router:tokens() | undefined:: Extra tokens for the host.">>},
{comment,<<>>},
{comment,<<"Return the extra tokens from matching against `...` during routing.">>},
{comment,<<>>},
{comment,<<"=== host_url(Req) -> HostURL">>},
{comment,<<>>},
{comment,<<"HostURL = binary() | undefined:: Requested URL, without the path component.">>},
{comment,<<>>},
{comment,<<"Return the requested URL excluding the path component.">>},
{comment,<<>>},
{comment,<<"This function will always return `undefined` until the">>},
{comment,<<"`cowboy_router` middleware has been executed.">>},
{comment,<<>>},
{comment,<<"=== match_cookies(Fields, Req) -> Map">>},
{comment,<<>>},
{comment,<<"Fields = cowboy:fields():: Cookie fields match rules.">>},
{comment,<<"Map = map():: Cookie fields matched.">>},
{comment,<<>>},
{comment,<<"Match cookies against the given fields.">>},
{comment,<<>>},
{comment,<<"Cowboy will only return the cookie values specified in the">>},
{comment,<<"fields list, and ignore all others. Fields can be either">>},
{comment,<<"the name of the cookie requested; the name along with a">>},
{comment,<<"list of constraints; or the name, a list of constraints">>},
{comment,<<"and a default value in case the cookie is missing.">>},
{comment,<<>>},
{comment,<<"This function will crash if the cookie is missing and no">>},
{comment,<<"default value is provided. This function will also crash">>},
{comment,<<"if a constraint fails.">>},
{comment,<<>>},
{comment,<<"The name of the cookie must be provided as an atom. The">>},
{comment,<<"key of the returned map will be that atom. The value may">>},
{comment,<<"be converted through the use of constraints, making this">>},
{comment,<<"function able to extract, validate and convert values all">>},
{comment,<<"in one step.">>},
{comment,<<>>},
{comment,<<"=== match_qs(Fields, Req) -> Map">>},
{comment,<<>>},
{comment,<<"Fields = cowboy:fields():: Query string fields match rules.">>},
{comment,<<"Map = map():: Query string fields matched.">>},
{comment,<<>>},
{comment,<<"Match the query string against the given fields.">>},
{comment,<<>>},
{comment,<<"Cowboy will only return the query string values specified">>},
{comment,<<"in the fields list, and ignore all others. Fields can be">>},
{comment,<<"either the key requested; the key along with a list of">>},
{comment,<<"constraints; or the key, a list of constraints and a">>},
{comment,<<"default value in case the key is missing.">>},
{comment,<<>>},
{comment,<<"This function will crash if the key is missing and no">>},
{comment,<<"default value is provided. This function will also crash">>},
{comment,<<"if a constraint fails.">>},
{comment,<<>>},
{comment,<<"The key must be provided as an atom. The key of the">>},
{comment,<<"returned map will be that atom. The value may be converted">>},
{comment,<<"through the use of constraints, making this function able">>},
{comment,<<"to extract, validate and convert values all in one step.">>},
{comment,<<>>},
{comment,<<"=== meta(Name, Req) -> meta(Name, Req, undefined)">>},
{comment,<<>>},
{comment,<<"Alias for `cowboy_req:meta/3`.">>},
{comment,<<>>},
{comment,<<"=== meta(Name, Req, Default) -> Value">>},
{comment,<<>>},
{comment,<<"Name = atom():: Metadata name.">>},
{comment,<<"Default = any():: Default value.">>},
{comment,<<"Value = any():: Metadata value.">>},
{comment,<<>>},
{comment,<<"Return metadata about the request.">>},
{comment,<<>>},
{comment,<<"=== method(Req) -> Method">>},
{comment,<<>>},
{comment,<<"Method = binary():: Request method.">>},
{comment,<<>>},
{comment,<<"Return the method.">>},
{comment,<<>>},
{comment,<<"Methods are case sensitive. Standard methods are always uppercase.">>},
{comment,<<>>},
{comment,<<"=== parse_cookies(Req) -> [{Name, Value}]">>},
{comment,<<>>},
{comment,<<"Name = binary():: Cookie name.">>},
{comment,<<"Value = binary():: Cookie value.">>},
{comment,<<>>},
{comment,<<"Parse and return all cookies.">>},
{comment,<<>>},
{comment,<<"Cookie names are case sensitive.">>},
{comment,<<>>},
{comment,<<"=== parse_header(Name, Req) -> see below">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:parse_header/3`.">>},
{comment,<<>>},
{comment,<<"The `parse_header/2` function will call `parser_header/3` with a">>},
{comment,<<"different default value depending on the header being parsed. The">>},
{comment,<<"following table summarizes the default values used.">>},
{comment,<<>>},
{comment,<<"[cols=\"<,^\",options=\"header\"]">>},
{comment,<<"|===">>},
{comment,<<"| Header name | Header value">>},
{comment,<<"| content-length | `0`">>},
{comment,<<"| cookie | `[]`">>},
{comment,<<"| transfer-encoding | `[<<\"identity\">>]`">>},
{comment,<<"| Any other header | `undefined`">>},
{comment,<<"|===">>},
{comment,<<>>},
{comment,<<"=== parse_header(Name, Req, Default) -> ParsedValue | Default">>},
{comment,<<>>},
{comment,<<"Name = binary():: Request header name.">>},
{comment,<<"Default = any():: Default value.">>},
{comment,<<"ParsedValue - see below:: Parsed request header value.">>},
{comment,<<>>},
{comment,<<"Parse the given header.">>},
{comment,<<>>},
{comment,<<"While header names are case insensitive, this function expects">>},
{comment,<<"the name to be a lowercase binary.">>},
{comment,<<>>},
{comment,<<"The parsed value differs depending on the header being parsed. The">>},
{comment,<<"following table summarizes the different types returned.">>},
{comment,<<>>},
{comment,<<"[cols=\"<,^\",options=\"header\"]">>},
{comment,<<"|===">>},
{comment,<<"| Header name | Type of parsed header value">>},
{comment,<<"| accept | `[{{Type, SubType, Params}, Quality, AcceptExt}]`">>},
{comment,<<"| accept-charset | `[{Charset, Quality}]`">>},
{comment,<<"| accept-encoding | `[{Encoding, Quality}]`">>},
{comment,<<"| accept-language | `[{LanguageTag, Quality}]`">>},
{comment,<<"| authorization | `{AuthType, Credentials}`">>},
{comment,<<"| content-length | `non_neg_integer()`">>},
{comment,<<"| content-type | `{Type, SubType, ContentTypeParams}`">>},
{comment,<<"| cookie | `[{binary(), binary()}]`">>},
{comment,<<"| expect | `[Expect \\| {Expect, ExpectValue, Params}]`">>},
{comment,<<"| if-match | `'*' \\| [{weak \\| strong, OpaqueTag}]`">>},
{comment,<<"| if-modified-since | `calendar:datetime()`">>},
{comment,<<"| if-none-match | `'*' \\| [{weak \\| strong, OpaqueTag}]`">>},
{comment,<<"| if-unmodified-since | `calendar:datetime()`">>},
{comment,<<"| range | `{Unit, [Range]}`">>},
{comment,<<"| sec-websocket-protocol | `[binary()]`">>},
{comment,<<"| transfer-encoding | `[binary()]`">>},
{comment,<<"| upgrade | `[binary()]`">>},
{comment,<<"| x-forwarded-for | `[binary()]`">>},
{comment,<<"|===">>},
{comment,<<>>},
{comment,<<"Types for the above table:">>},
{comment,<<>>},
{comment,<<"* Type = SubType = Charset = Encoding = LanguageTag = binary()">>},
{comment,<<"* AuthType = Expect = OpaqueTag = Unit = binary()">>},
{comment,<<"* Params = ContentTypeParams = [{binary(), binary()}]">>},
{comment,<<"* Quality = 0..1000">>},
{comment,<<"* AcceptExt = [{binary(), binary()} | binary()]">>},
{comment,<<"* Credentials - see below">>},
{comment,<<"* Range = {non_neg_integer(), non_neg_integer() | infinity} | neg_integer()">>},
{comment,<<>>},
{comment,<<"The cookie names and values, the values of the sec-websocket-protocol">>},
{comment,<<"and x-forwarded-for headers, the values in `AcceptExt` and `Params`,">>},
{comment,<<"the authorization `Credentials`, the `ExpectValue` and `OpaqueTag`">>},
{comment,<<"are case sensitive. All values in `ContentTypeParams` are case sensitive">>},
{comment,<<"except the value of the charset parameter, which is case insensitive.">>},
{comment,<<"All other values are case insensitive and will be returned as lowercase.">>},
{comment,<<>>},
{comment,<<"The headers accept, accept-encoding and cookie headers can return">>},
{comment,<<"an empty list. Some other headers are expected to have a value if provided">>},
{comment,<<"and may crash if the value is missing.">>},
{comment,<<>>},
{comment,<<"The authorization header parsing code currently only supports basic">>},
{comment,<<"HTTP authentication. The `Credentials` type is thus `{Username, Password}`">>},
{comment,<<"with `Username` and `Password` being `binary()`.">>},
{comment,<<>>},
{comment,<<"The range header value `Range` can take three forms:">>},
{comment,<<>>},
{comment,<<"* `{From, To}`: from `From` to `To` units">>},
{comment,<<"* `{From, infinity}`: everything after `From` units">>},
{comment,<<"* `-Final`: the final `Final` units">>},
{comment,<<>>},
{comment,<<"An `undefined` tuple will be returned if Cowboy doesn't know how">>},
{comment,<<"to parse the requested header.">>},
{comment,<<>>},
{comment,<<"=== parse_qs(Req) -> [{Name, Value}]">>},
{comment,<<>>},
{comment,<<"Name = binary():: Query string field name.">>},
{comment,<<"Value = binary() | true:: Query string field value.">>},
{comment,<<>>},
{comment,<<"Return the request's query string as a list of tuples.">>},
{comment,<<>>},
{comment,<<"The atom `true` is returned for keys which have no value.">>},
{comment,<<"Keys with no value are different from keys with an empty">>},
{comment,<<"value in that they do not have a `=` indicating the presence">>},
{comment,<<"of a value.">>},
{comment,<<>>},
{comment,<<"=== path(Req) -> Path">>},
{comment,<<>>},
{comment,<<"Path = binary():: Requested path.">>},
{comment,<<>>},
{comment,<<"Return the requested path.">>},
{comment,<<>>},
{comment,<<"=== path_info(Req) -> PathInfo">>},
{comment,<<>>},
{comment,<<"PathInfo = cowboy_router:tokens() | undefined:: Extra tokens for the path.">>},
{comment,<<>>},
{comment,<<"Return the extra tokens from matching against `...` during routing.">>},
{comment,<<>>},
{comment,<<"=== peer(Req) -> Peer">>},
{comment,<<>>},
{comment,<<"Peer = `{inet:ip_address(), inet:port_number()}`:: Peer IP address and port number.">>},
{comment,<<>>},
{comment,<<"Return the client's IP address and port number.">>},
{comment,<<>>},
{comment,<<"=== port(Req) -> Port">>},
{comment,<<>>},
{comment,<<"Port = inet:port_number():: Requested port number.">>},
{comment,<<>>},
{comment,<<"Return the request's port.">>},
{comment,<<>>},
{comment,<<"The port returned by this function is obtained by parsing">>},
{comment,<<"the host header. It may be different than the actual port">>},
{comment,<<"the client used to connect to the Cowboy server.">>},
{comment,<<>>},
{comment,<<"=== qs(Req) -> QueryString">>},
{comment,<<>>},
{comment,<<"QueryString = binary():: Unprocessed query string.">>},
{comment,<<>>},
{comment,<<"Return the request's query string.">>},
{comment,<<>>},
{comment,<<"=== set_meta(Name, Value, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"Name = atom():: Metadata name.">>},
{comment,<<"Value = any():: Metadata value.">>},
{comment,<<>>},
{comment,<<"Set metadata about the request.">>},
{comment,<<>>},
{comment,<<"An existing value will be overwritten.">>},
{comment,<<>>},
{comment,<<"=== url(Req) -> URL">>},
{comment,<<>>},
{comment,<<"URL = binary() | undefined:: Requested URL.">>},
{comment,<<>>},
{comment,<<"Return the requested URL.">>},
{comment,<<>>},
{comment,<<"This function will always return `undefined` until the">>},
{comment,<<"`cowboy_router` middleware has been executed.">>},
{comment,<<>>},
{comment,<<"=== version(Req) -> Version">>},
{comment,<<>>},
{comment,<<"Version = cowboy:http_version():: Client's advertised HTTP version.">>},
{comment,<<>>},
{comment,<<"Return the HTTP version used for this request.">>},
{comment,<<>>},
{comment,<<"== Request body related exports">>},
{comment,<<>>},
{comment,<<"=== body(Req) -> body(Req, [])">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:body/2`.">>},
{comment,<<>>},
{comment,<<"=== body(Req, Opts) -> {ok, Data, Req2} | {more, Data, Req2}">>},
{comment,<<>>},
{comment,<<"Opts = [body_opt()]:: Request body reading options.">>},
{comment,<<"Data = binary():: Data read from the body.">>},
{comment,<<>>},
{comment,<<"Read the request body.">>},
{comment,<<>>},
{comment,<<"This function will read a chunk of the request body. If there is">>},
{comment,<<"more data to be read after this function call, then a `more` tuple">>},
{comment,<<"is returned. Otherwise an `ok` tuple is returned.">>},
{comment,<<>>},
{comment,<<"Cowboy will automatically send a `100 Continue` reply if">>},
{comment,<<"required. If this behavior is not desirable, it can be disabled">>},
{comment,<<"by setting the `continue` option to `false`.">>},
{comment,<<>>},
{comment,<<"Cowboy will by default attempt to read up to 8MB of the body,">>},
{comment,<<"but in chunks of 1MB. It will use a timeout of 15s per chunk.">>},
{comment,<<"All these values can be changed using the `length`, `read_length`">>},
{comment,<<"and `read_timeout` options respectively. Note that the size">>},
{comment,<<"of the data may not be the same as requested as the decoding">>},
{comment,<<"functions may grow or shrink it, and Cowboy makes not attempt">>},
{comment,<<"at returning an exact amount.">>},
{comment,<<>>},
{comment,<<"Cowboy will properly handle chunked transfer-encoding by">>},
{comment,<<"default. If any other transfer-encoding or content-encoding">>},
{comment,<<"has been used for the request, custom decoding functions">>},
{comment,<<"can be used. The `content_decode` and `transfer_decode`">>},
{comment,<<"options allow setting the decode functions manually.">>},
{comment,<<>>},
{comment,<<"After the body has been streamed fully, Cowboy will remove">>},
{comment,<<"the transfer-encoding header from the Req object, and add">>},
{comment,<<"the content-length header if it wasn't already there.">>},
{comment,<<>>},
{comment,<<"This function can only be called once. Cowboy will not cache">>},
{comment,<<"the result of this call.">>},
{comment,<<>>},
{comment,<<"=== body_length(Req) -> Length">>},
{comment,<<>>},
{comment,<<"Length = non_neg_integer() | undefined:: Length of the request body.">>},
{comment,<<>>},
{comment,<<"Return the length of the request body.">>},
{comment,<<>>},
{comment,<<"The length will only be returned if the request does not">>},
{comment,<<"use any transfer-encoding and if the content-length header">>},
{comment,<<"is present.">>},
{comment,<<>>},
{comment,<<"=== body_qs(Req) -> body_qs(Req, [{length, 64000}, {read_length, 64000}, {read_timeout, 5000}])">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:body_qs/2`.">>},
{comment,<<>>},
{comment,<<"=== body_qs(Req, Opts) -> {ok, [{Name, Value}], Req2} | {badlength, Req2}">>},
{comment,<<>>},
{comment,<<"Opts = [body_opt()]:: Request body reading options.">>},
{comment,<<"Name = binary():: Field name.">>},
{comment,<<"Value = binary() | true:: Field value.">>},
{comment,<<>>},
{comment,<<"Return the request body as a list of tuples.">>},
{comment,<<>>},
{comment,<<"This function will parse the body assuming the content-type">>},
{comment,<<"application/x-www-form-urlencoded, commonly used for the">>},
{comment,<<"query string.">>},
{comment,<<>>},
{comment,<<"This function calls `body/2` for reading the body, with the">>},
{comment,<<"same options it received. By default it will attempt to read">>},
{comment,<<"a body of 64KB in one chunk, with a timeout of 5s. If the">>},
{comment,<<"body is larger then a `badlength` tuple is returned.">>},
{comment,<<>>},
{comment,<<"This function can only be called once. Cowboy will not cache">>},
{comment,<<"the result of this call.">>},
{comment,<<>>},
{comment,<<"=== has_body(Req) -> boolean()">>},
{comment,<<>>},
{comment,<<"Return whether the request has a body.">>},
{comment,<<>>},
{comment,<<"=== part(Req) -> part(Req, [{length, 64000}, {read_length, 64000}, {read_timeout, 5000}])">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:part/2`.">>},
{comment,<<>>},
{comment,<<"=== part(Req, Opts) -> {ok, Headers, Req2} | {done, Req2}">>},
{comment,<<>>},
{comment,<<"Opts = [body_opt()]:: Request body reading options.">>},
{comment,<<"Headers = cow_multipart:headers():: Part's headers.">>},
{comment,<<>>},
{comment,<<"Read the headers for the next part of the multipart message.">>},
{comment,<<>>},
{comment,<<"Cowboy will skip any data remaining until the beginning of">>},
{comment,<<"the next part. This includes the preamble to the multipart">>},
{comment,<<"message but also the body of a previous part if it hasn't">>},
{comment,<<"been read. Both are skipped automatically when calling this">>},
{comment,<<"function.">>},
{comment,<<>>},
{comment,<<"The headers returned are MIME headers, NOT HTTP headers.">>},
{comment,<<"They can be parsed using the functions from the `cow_multipart`">>},
{comment,<<"module. In addition, the `cow_multipart:form_data/1` function">>},
{comment,<<"can be used to quickly figure out `multipart/form-data` messages.">>},
{comment,<<"It takes the list of headers and returns whether this part is">>},
{comment,<<"a simple form field or a file being uploaded.">>},
{comment,<<>>},
{comment,<<"Note that once a part has been read, or skipped, it cannot">>},
{comment,<<"be read again.">>},
{comment,<<>>},
{comment,<<"This function calls `body/2` for reading the body, with the">>},
{comment,<<"same options it received. By default it will only read chunks">>},
{comment,<<"of 64KB with a timeout of 5s. This is tailored for reading">>},
{comment,<<"part headers, not for skipping the previous part's body.">>},
{comment,<<"You might want to consider skipping large parts manually.">>},
{comment,<<>>},
{comment,<<"=== part_body(Req) -> part_body(Req, [])">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:part_body/2`.">>},
{comment,<<>>},
{comment,<<"=== part_body(Req, Opts) -> {ok, Data, Req2} | {more, Data, Req2}">>},
{comment,<<>>},
{comment,<<"Opts = [body_opt()]:: Request body reading options.">>},
{comment,<<"Data = binary():: Part's body.">>},
{comment,<<>>},
{comment,<<"Read the body of the current part of the multipart message.">>},
{comment,<<>>},
{comment,<<"This function calls `body/2` for reading the body, with the">>},
{comment,<<"same options it received. It uses the same defaults.">>},
{comment,<<>>},
{comment,<<"If there are more data to be read from the socket for this">>},
{comment,<<"part, the function will return what it could read inside a">>},
{comment,<<"`more` tuple. Otherwise, it will return an `ok` tuple.">>},
{comment,<<>>},
{comment,<<"Calling this function again after receiving a `more` tuple">>},
{comment,<<"will return another chunk of body. The last chunk will be">>},
{comment,<<"returned inside an `ok` tuple.">>},
{comment,<<>>},
{comment,<<"Note that once the body has been read, fully or partially,">>},
{comment,<<"it cannot be read again.">>},
{comment,<<>>},
{comment,<<"== Response related exports">>},
{comment,<<>>},
{comment,<<"=== chunk(Data, Req) -> ok">>},
{comment,<<>>},
{comment,<<"Data = iodata():: Chunk data to be sent.">>},
{comment,<<>>},
{comment,<<"Send a chunk of data.">>},
{comment,<<>>},
{comment,<<"This function should be called as many times as needed">>},
{comment,<<"to send data chunks after calling `chunked_reply/{2,3}`.">>},
{comment,<<>>},
{comment,<<"When the method is HEAD, no data will actually be sent.">>},
{comment,<<>>},
{comment,<<"If the request uses HTTP/1.0, the data is sent directly">>},
{comment,<<"without wrapping it in an HTTP/1.1 chunk, providing">>},
{comment,<<"compatibility with older clients.">>},
{comment,<<>>},
{comment,<<"=== chunked_reply(StatusCode, Req) -> chunked_reply(StatusCode, [], Req)">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:chunked_reply/3`.">>},
{comment,<<>>},
{comment,<<"=== chunked_reply(StatusCode, Headers, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"StatusCode = cowboy:http_status():: Response status code.">>},
{comment,<<"Headers = cowboy:http_headers():: Response headers.">>},
{comment,<<>>},
{comment,<<"Send a response using chunked transfer-encoding.">>},
{comment,<<>>},
{comment,<<"This function effectively sends the response status line">>},
{comment,<<"and headers to the client.">>},
{comment,<<>>},
{comment,<<"This function will not send any body set previously. After">>},
{comment,<<"this call the handler must use the `chunk/2` function">>},
{comment,<<"repeatedly to send the body in as many chunks as needed.">>},
{comment,<<>>},
{comment,<<"If the request uses HTTP/1.0, the data is sent directly">>},
{comment,<<"without wrapping it in an HTTP/1.1 chunk, providing">>},
{comment,<<"compatibility with older clients.">>},
{comment,<<>>},
{comment,<<"This function can only be called once, with the exception">>},
{comment,<<"of overriding the response in the `onresponse` hook.">>},
{comment,<<>>},
{comment,<<"=== continue(Req) -> ok">>},
{comment,<<>>},
{comment,<<"Send a 100 Continue intermediate reply.">>},
{comment,<<>>},
{comment,<<"This reply is required before the client starts sending the">>},
{comment,<<"body when the request contains the `expect` header with the">>},
{comment,<<"`100-continue` value.">>},
{comment,<<>>},
{comment,<<"Cowboy will send this automatically when required. However">>},
{comment,<<"you may want to do it manually by disabling this behavior">>},
{comment,<<"with the `continue` body option and then calling this">>},
{comment,<<"function.">>},
{comment,<<>>},
{comment,<<"=== delete_resp_header(Name, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"Name = binary():: Response header name.">>},
{comment,<<>>},
{comment,<<"Delete the given response header.">>},
{comment,<<>>},
{comment,<<"While header names are case insensitive, this function expects">>},
{comment,<<"the name to be a lowercase binary.">>},
{comment,<<>>},
{comment,<<"=== has_resp_body(Req) -> boolean()">>},
{comment,<<>>},
{comment,<<"Return whether a response body has been set.">>},
{comment,<<>>},
{comment,<<"This function will return false if a response body has">>},
{comment,<<"been set with a length of 0.">>},
{comment,<<>>},
{comment,<<"=== has_resp_header(Name, Req) -> boolean()">>},
{comment,<<>>},
{comment,<<"Name = binary():: Response header name.">>},
{comment,<<>>},
{comment,<<"Return whether the given response header has been set.">>},
{comment,<<>>},
{comment,<<"While header names are case insensitive, this function expects">>},
{comment,<<"the name to be a lowercase binary.">>},
{comment,<<>>},
{comment,<<"=== reply(StatusCode, Req) -> reply(StatusCode, [], Req)">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:reply/3`.">>},
{comment,<<>>},
{comment,<<"=== reply(StatusCode, Headers, Req) - see below">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:reply/4`, with caveats.">>},
{comment,<<>>},
{comment,<<"=== reply(StatusCode, Headers, Body, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"StatusCode = cowboy:http_status():: Response status code.">>},
{comment,<<"Headers = cowboy:http_headers():: Response headers.">>},
{comment,<<"Body = iodata():: Response body.">>},
{comment,<<>>},
{comment,<<"Send a response.">>},
{comment,<<>>},
{comment,<<"This function effectively sends the response status line,">>},
{comment,<<"headers and body to the client, in a single send function">>},
{comment,<<"call.">>},
{comment,<<>>},
{comment,<<"The `reply/2` and `reply/3` functions will send the body">>},
{comment,<<"set previously, if any. The `reply/4` function overrides">>},
{comment,<<"any body set previously and sends `Body` instead.">>},
{comment,<<>>},
{comment,<<"If a body function was set, and `reply/2` or `reply/3` was">>},
{comment,<<"used, it will be called before returning.">>},
{comment,<<>>},
{comment,<<"No more data can be sent to the client after this function">>},
{comment,<<"returns.">>},
{comment,<<>>},
{comment,<<"This function can only be called once, with the exception">>},
{comment,<<"of overriding the response in the `onresponse` hook.">>},
{comment,<<>>},
{comment,<<"=== set_resp_body(Body, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"Body = iodata():: Response body.">>},
{comment,<<>>},
{comment,<<"Set a response body.">>},
{comment,<<>>},
{comment,<<"This body will not be sent if `chunked_reply/{2,3}` or">>},
{comment,<<"`reply/4` is used, as they override it.">>},
{comment,<<>>},
{comment,<<"=== set_resp_body_fun(Fun, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"Alias of `cowboy_req:set_resp_body_fun/3`.">>},
{comment,<<>>},
{comment,<<"=== set_resp_body_fun(Length, Fun, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"Fun = fun((Socket, Transport) -> ok):: Fun that will send the response body.">>},
{comment,<<"Socket = inet:socket():: Socket for this connection.">>},
{comment,<<"Transport = module():: Transport module for this socket.">>},
{comment,<<"Length = non_neg_integer():: Length of the response body.">>},
{comment,<<>>},
{comment,<<"Set a fun for sending the response body.">>},
{comment,<<>>},
{comment,<<"If a `Length` is provided, it will be sent in the">>},
{comment,<<"content-length header in the response. It is recommended">>},
{comment,<<"to set the length if it can be known in advance. Otherwise,">>},
{comment,<<"the transfer-encoding header will be set to identity.">>},
{comment,<<>>},
{comment,<<"This function will only be called if the response is sent">>},
{comment,<<"using the `reply/2` or `reply/3` function.">>},
{comment,<<>>},
{comment,<<"The fun will receive the Ranch `Socket` and `Transport` as">>},
{comment,<<"arguments. Only send and sendfile operations are supported.">>},
{comment,<<>>},
{comment,<<"=== set_resp_body_fun(chunked, Fun, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"Fun = fun((ChunkFun) -> ok):: Fun that will send the response body.">>},
{comment,<<"ChunkFun = fun((iodata()) -> ok):: Fun to call for every chunk to be sent.">>},
{comment,<<>>},
{comment,<<"Set a fun for sending the response body using chunked transfer-encoding.">>},
{comment,<<>>},
{comment,<<"This function will only be called if the response is sent">>},
{comment,<<"using the `reply/2` or `reply/3` function.">>},
{comment,<<>>},
{comment,<<"The fun will receive another fun as argument. This fun is to">>},
{comment,<<"be used to send chunks in a similar way to the `chunk/2` function,">>},
{comment,<<"except the fun only takes one argument, the data to be sent in">>},
{comment,<<"the chunk.">>},
{comment,<<>>},
{comment,<<"=== set_resp_cookie(Name, Value, Opts, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"Name = iodata():: Cookie name.">>},
{comment,<<"Value = iodata():: Cookie value.">>},
{comment,<<"Opts = cookie_opts():: Cookie options.">>},
{comment,<<>>},
{comment,<<"Set a cookie in the response.">>},
{comment,<<>>},
{comment,<<"Cookie names are case sensitive.">>},
{comment,<<>>},
{comment,<<"=== set_resp_header(Name, Value, Req) -> Req2">>},
{comment,<<>>},
{comment,<<"Name = binary():: Response header name.">>},
{comment,<<"Value = iodata():: Response header value.">>},
{comment,<<>>},
{comment,<<"Set a response header.">>},
{comment,<<>>},
{comment,<<"You should use `set_resp_cookie/4` instead of this function">>},
{comment,<<"to set cookies.">>}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.