From b2d4e41dcda3c2964c8a865482129a7fdf9e55a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 7 Nov 2016 18:20:55 +0200 Subject: Update docs --- .../2.0/manual/cowboy_req.match_cookies/index.html | 261 +++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 docs/en/cowboy/2.0/manual/cowboy_req.match_cookies/index.html (limited to 'docs/en/cowboy/2.0/manual/cowboy_req.match_cookies/index.html') diff --git a/docs/en/cowboy/2.0/manual/cowboy_req.match_cookies/index.html b/docs/en/cowboy/2.0/manual/cowboy_req.match_cookies/index.html new file mode 100644 index 00000000..f0b3fb86 --- /dev/null +++ b/docs/en/cowboy/2.0/manual/cowboy_req.match_cookies/index.html @@ -0,0 +1,261 @@ + + + + + + + + + + + + Nine Nines: cowboy_req:match_cookies(3) + + + + + + + + + + + + + + + + + + +
+
+
+
+ +

cowboy_req:match_cookies(3)

+ +
+

Name

+
+

cowboy_req:match_cookies - Match cookies against constraints

+
+
+
+

Description

+
+
+
+
match_cookies(Fields :: cowboy:fields(), Req :: cowboy_req:req())
+    -> #{atom() => any()}
+

Parse the cookies and match specific values against +constraints.

+

Cowboy will only return the cookie values specified in the +fields list, and ignore all others. Fields can be either +the name of the cookie requested; the name along with a +list of constraints; or the name, a list of constraints +and a default value in case the cookie is missing.

+

This function will crash if the cookie is missing and no +default value is provided. This function will also crash +if a constraint fails.

+

The name of the cookie must be provided as an atom. The +key of the returned map will be that atom. The value may +be converted through the use of constraints, making this +function able to extract, validate and convert values all +in one step.

+
+
+
+

Arguments

+
+
+
+Fields +
+
+

+Cookies to retrieve. +

+

See cowboy(3) for a complete description.

+
+
+Req +
+
+

+The Req object. +

+
+
+
+
+
+

Return value

+
+

Desired values are returned as a map. The key is the atom +that was given in the list of fields, and the value is the +optionally converted value after applying constraints.

+

The map contains the same keys that were given in the fields.

+

An exception is triggered when the match fails.

+
+
+
+

Changelog

+
+
    +
  • +

    +2.0: Function introduced. +

    +
  • +
+
+
+
+

Examples

+
+
+
Match fields
+
+
%% ID and Lang are binaries.
+#{id := ID, lang := Lang}
+    = cowboy_req:match_cookies([id, lang], Req).
+
+
Match fields and apply constraints
+
+
%% ID is an integer and Lang a non-empty binary.
+#{id := ID, lang := Lang}
+    = cowboy_req:match_cookies([{id, int}, {lang, nonempty}], Req).
+
+
Match fields with default values
+
+
#{lang := Lang}
+    = cowboy_req:match_cookies([{lang, [], <<"en-US">>}], Req).
+
+
+ + + + + + +
+ +
+ + +

+ Cowboy + 2.0 + Function Reference + +

+ + + +

Navigation

+ +

Version select

+ + +
+
+
+
+ + + + + + + + + + + + -- cgit v1.2.3