Debian Codegraph @

doc/src/manual/cowboy_req.filter_cookies.asciidoc

raw
1 = cowboy_req:filter_cookies(3)
2
3 == Name
4
5 cowboy_req:filter_cookies - Filter cookie headers
6
7 == Description
8
9 [source,erlang]
10 ----
11 filter_cookies(Names, Req) -> Req
12
13 Names :: [atom() | binary()]
14 ----
15
16 Filter cookie headers.
17
18 This function is meant to be used before attempting to parse
19 or match cookies in order to remove cookies that are not
20 relevant and are potentially malformed. Because Cowboy by
21 default crashes on malformed cookies, this function allows
22 processing requests that would otherwise result in a 400
23 error.
24
25 Malformed cookies are unfortunately fairly common due to
26 the string-based interface provided by browsers and this
27 function provides a middle ground between Cowboy's strict
28 behavior and chaotic real world use cases.
29
30 Note that there may still be crashes even after filtering
31 cookies because this function does not correct malformed
32 values. Cookies that have malformed values should probably
33 be unset in an error response or in a redirect.
34
35 This function can be called even if there are no cookies
36 in the request.
37
38 == Arguments
39
40 Names::
41
42 The cookies that should be kept.
43
44 Req::
45
46 The Req object.
47
48 == Return value
49
50 The Req object is returned with its cookie header value
51 filtered.
52
53 == Changelog
54
55 * *2.7*: Function introduced.
56
57 == Examples
58
59 .Filter then parse cookies
60 [source,erlang]
61 ----
62 Req = cowboy_req:filter_cookies([session_id, token], Req0),
63 Cookies = cowboy_req:parse_cookies(Req).
64 ----
65
66 == See also
67
68 link:man:cowboy_req(3)[cowboy_req(3)],
69 link:man:cowboy_req:parse_cookies(3)[cowboy_req:parse_cookies(3)],
70 link:man:cowboy_req:match_cookies(3)[cowboy_req:match_cookies(3)]