diff options
author | Loïc Hoguin <[email protected]> | 2018-04-04 13:13:37 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-04-04 13:13:37 +0200 |
commit | d2a3f2cedd7c00d0933222aed9c06b3149aa4db4 (patch) | |
tree | 4f1499bac639c782b250af0fbf0dec2064315813 /docs/en/cowboy/2.0/guide/req/index.html | |
parent | 1d654719f5fa6be67d2c95145872068665702cb7 (diff) | |
download | ninenines.eu-d2a3f2cedd7c00d0933222aed9c06b3149aa4db4.tar.gz ninenines.eu-d2a3f2cedd7c00d0933222aed9c06b3149aa4db4.tar.bz2 ninenines.eu-d2a3f2cedd7c00d0933222aed9c06b3149aa4db4.zip |
Cowboy 2.3.0
Diffstat (limited to 'docs/en/cowboy/2.0/guide/req/index.html')
-rw-r--r-- | docs/en/cowboy/2.0/guide/req/index.html | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/docs/en/cowboy/2.0/guide/req/index.html b/docs/en/cowboy/2.0/guide/req/index.html index 1b81cdfc..d6f7a2fd 100644 --- a/docs/en/cowboy/2.0/guide/req/index.html +++ b/docs/en/cowboy/2.0/guide/req/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.30.2" /> + <meta name="generator" content="Hugo 0.37.1" /> <title>Nine Nines: The Req object</title> @@ -91,7 +91,7 @@ head. The following example sends a simple "Hello world!" response when the <code>method</code> is GET, and a 405 error otherwise.</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -146,14 +146,14 @@ where the crash occurred.</p></div> <div class="sectionbody"> <div class="paragraph"><p>The request method can be retrieved directly:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt>#{<span style="color: #FF6600">method</span> <span style="color: #990000">:=</span> <span style="color: #009900">Method</span>} <span style="color: #990000">=</span> <span style="color: #009900">Req</span><span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>Or using a function:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -175,14 +175,14 @@ want to redirect HTTP/1.1 clients to use Websocket, while HTTP/2 clients keep using HTTP/2.</p></div> <div class="paragraph"><p>The HTTP version can be retrieved directly:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt>#{<span style="color: #FF6600">version</span> <span style="color: #990000">:=</span> <span style="color: #009900">Version</span>} <span style="color: #990000">=</span> <span style="color: #009900">Req</span><span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>Or using a function:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -198,7 +198,7 @@ atoms.</p></div> <div class="paragraph"><p>The scheme, host, port, path and query string components of the effective request URI can all be retrieved directly:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -211,7 +211,7 @@ http://www.gnu.org/software/src-highlite --> } <span style="color: #990000">=</span> <span style="color: #009900">Req</span><span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>Or using the related functions:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -230,7 +230,7 @@ for requests on secure HTTP/1.1 or HTTP/2 connections.</p></div> the <code>cowboy_req:uri/1,2</code> function. By default, an absolute URI is returned:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -240,7 +240,7 @@ http://www.gnu.org/software/src-highlite --> or all of the components. Various URIs or URI formats can be generated this way, including the origin form:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -248,7 +248,7 @@ http://www.gnu.org/software/src-highlite --> <span style="color: #009900">URI</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:uri</span></span>(<span style="color: #009900">Req</span>, #{<span style="color: #0000FF">host</span> <span style="color: #990000">=></span> <span style="color: #000080">undefined</span>})<span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>The protocol relative form:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -256,14 +256,14 @@ http://www.gnu.org/software/src-highlite --> <span style="color: #009900">URI</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:uri</span></span>(<span style="color: #009900">Req</span>, #{<span style="color: #0000FF">scheme</span> <span style="color: #990000">=></span> <span style="color: #000080">undefined</span>})<span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>The absolute URI without a query string:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt><span style="color: #009900">URI</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:uri</span></span>(<span style="color: #009900">Req</span>, #{<span style="color: #0000FF">qs</span> <span style="color: #990000">=></span> <span style="color: #000080">undefined</span>})<span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>A different host:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -280,7 +280,7 @@ They are only available after the routing.</p></div> <div class="paragraph"><p>Cowboy provides functions to retrieve one or all bindings.</p></div> <div class="paragraph"><p>To retrieve a single value:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -289,14 +289,14 @@ http://www.gnu.org/software/src-highlite --> <code>undefined</code> will be returned. A different default value can be provided:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt><span style="color: #009900">Value</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:binding</span></span>(<span style="color: #FF6600">userid</span>, <span style="color: #009900">Req</span>, <span style="color: #993399">42</span>)<span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>To retrieve everything that was bound:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -306,14 +306,14 @@ http://www.gnu.org/software/src-highlite --> or path segments at once using the <code>...</code> qualifier.</p></div> <div class="paragraph"><p>To retrieve the segments captured from the host name:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt><span style="color: #009900">HostInfo</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:host_info</span></span>(<span style="color: #009900">Req</span>)<span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>And the path segments:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -328,7 +328,7 @@ in the route.</p></div> <div class="paragraph"><p>Cowboy provides two functions to access query parameters. You can use the first to get the entire list of parameters.</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -351,7 +351,7 @@ only the parameters you are interested in, and at the same time do any post processing you require using <a href="../constraints">constraints</a>. This function returns a map.</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -361,7 +361,7 @@ snippet will crash when the <code>id</code> parameter is not an integer, or when the <code>lang</code> parameter is empty. At the same time, the value for <code>id</code> will be converted to an integer term:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -370,7 +370,7 @@ http://www.gnu.org/software/src-highlite --> if the <code>lang</code> key is not found. It will not be used if the key is found but has an empty value.</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -390,7 +390,7 @@ ensure that only one value was passed through.</p></div> or parsed into a more meaningful representation.</p></div> <div class="paragraph"><p>The get the raw value:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -401,21 +401,21 @@ regardless of the underlying protocol.</p></div> <div class="paragraph"><p>When the header is missing from the request, <code>undefined</code> will be returned. A different default can be provided:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt><span style="color: #009900">HeaderVal</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:header</span></span>(<span style="color: #990000"><<</span><span style="color: #FF0000">"content-type"</span><span style="color: #990000">>></span>, <span style="color: #009900">Req</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"text/plain"</span><span style="color: #990000">>></span>)<span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>All headers can be retrieved at once, either directly:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt>#{<span style="color: #FF6600">headers</span> <span style="color: #990000">:=</span> <span style="color: #009900">AllHeaders</span>} <span style="color: #990000">=</span> <span style="color: #009900">Req</span><span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>Or using a function:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -424,7 +424,7 @@ http://www.gnu.org/software/src-highlite --> headers. There is no function to parse all headers at once.</p></div> <div class="paragraph"><p>To parse a specific header:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -436,7 +436,7 @@ and default values can be found in the manual.</p></div> change the default value. Note that it should be the parsed value directly:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -451,14 +451,14 @@ http://www.gnu.org/software/src-highlite --> retrieved either directly or using a function.</p></div> <div class="paragraph"><p>To retrieve the peer directly:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt>#{<span style="color: #FF6600">peer</span> <span style="color: #990000">:=</span> {<span style="color: #009900">IP</span>, <span style="color: #009900">Port</span>}} <span style="color: #990000">=</span> <span style="color: #009900">Req</span><span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>And using a function:</p></div> <div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="content"><!-- Generator: GNU source-highlight by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -524,6 +524,8 @@ client itself. It may also be a proxy or a gateway.</p></div> + <li><a href="/docs/en/cowboy/2.3/guide">2.3</a></li> + <li><a href="/docs/en/cowboy/2.2/guide">2.2</a></li> <li><a href="/docs/en/cowboy/2.1/guide">2.1</a></li> |