1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
= gun_cookies(3)
== Name
gun_cookies - Cookie store engine
== Description
The `gun_cookies` module implements a cookie store engine.
It will be used by Gun when a cookie store is configured.
It also defines the interface and provides functions used
to implement cookie store backends.
== Callbacks
Cookie store backends implement the following interface.
Functions are organized by theme: initialization, querying,
storing and garbage collecting:
=== init
[source,erlang]
----
init(Opts :: any()) -> gun_cookies:store()
----
Initialize the cookie store.
=== query
[source,erlang]
----
query(State, URI) -> {ok, [Cookie], State}
URI :: uri_string:uri_map()
Cookie :: gun_cookies:cookie()
State :: any()
----
Query the store for the cookies for the given URI.
=== set_cookie_secure_match
[source,erlang]
----
set_cookie_secure_match(State, Match) -> match | nomatch
State :: any()
Match :: #{
name := binary(),
% secure_only := true,
domain := binary(),
path := binary()
}
----
Perform a secure match against cookies already in the store.
This is part of the heuristics that the cookie store engine
applies to decide whether the cookie must be stored.
The `secure_only` attribute is implied, it is not actually
passed in the argument.
=== set_cookie_get_exact_match
[source,erlang]
----
set_cookie_get_exact_match(State, Match)
-> {ok, gun_cookies:cookie(), State} | error
State :: any()
Match :: #{
name := binary(),
domain := binary(),
host_only := boolean(),
path := binary()
}
----
Perform an exact match against cookies already in the store.
This is part of the heuristics that the cookie store engine
applies to decide whether the cookie must be stored.
When a cookie is found, it must be returned so that it gets
updated. When nothing is found a new cookie will be stored.
=== store
[source,erlang]
----
store(State, gun_cookies:cookie())
-> {ok, State} | {error, any()}
State :: any()
----
Unconditionally store the cookie into the cookie store.
=== gc
[source,erlang]
----
gc(State) -> {ok, State}
State :: any()
----
Remove all cookies from the cookie store that are expired.
Other cookies may be removed as well, at the discretion
of the cookie store. For example excess cookies may be
removed to reduce the memory footprint.
=== session_gc
[source,erlang]
----
session_gc(State) -> {ok, State}
State :: any()
----
Remove all cookies from the cookie store that have the
`persistent` flag set to `false`.
== Exports
* link:man:gun_cookies:domain_match(3)[gun_cookies:domain_match(3)] - Cookie domain match
* link:man:gun_cookies:path_match(3)[gun_cookies:path_match(3)] - Cookie path match
== Types
=== cookie()
[source,erlang]
----
cookie() :: #{
name := binary(),
value := binary(),
domain := binary(),
path := binary(),
creation_time := calendar:datetime(),
last_access_time := calendar:datetime(),
expiry_time := calendar:datetime() | infinity,
persistent := boolean(),
host_only := boolean(),
secure_only := boolean(),
http_only := boolean(),
same_site := strict | lax | none
}
----
A cookie.
This contains the cookie name, value, attributes and flags.
This is the representation that the cookie store engine
and Gun expects. Cookies do not have to be kept in this
format in the cookie store backend.
=== store()
[source,erlang]
----
store() :: {module(), StoreState :: any()}
----
The cookie store.
This is a tuple containing the cookie store backend module
and its current state.
== Changelog
* *2.0*: Module introduced.
== See also
link:man:gun(7)[gun(7)],
link:man:gun_cookies_list(3)[gun_cookies_list(3)]
|