aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/guide/cookies.asciidoc
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-02-19 09:46:11 +0100
committerLoïc Hoguin <[email protected]>2017-02-19 09:46:11 +0100
commit91ae70b06c9cc486ea2c2cf91b94de799ceb53b2 (patch)
tree37cc4d2dffbaef0e103c1f834e7ae7117ffd51ca /doc/src/guide/cookies.asciidoc
parent87a05a12199cc9f0a569669d96d6c65761e8ff97 (diff)
downloadcowboy-91ae70b06c9cc486ea2c2cf91b94de799ceb53b2.tar.gz
cowboy-91ae70b06c9cc486ea2c2cf91b94de799ceb53b2.tar.bz2
cowboy-91ae70b06c9cc486ea2c2cf91b94de799ceb53b2.zip
Change the order of set_resp_cookie arguments
The Opts value is put last, to be more consistent with the rest of the cowboy_req module. Additionally a test handler was fixed which reduced the number of errors in http_SUITE.
Diffstat (limited to 'doc/src/guide/cookies.asciidoc')
-rw-r--r--doc/src/guide/cookies.asciidoc27
1 files changed, 12 insertions, 15 deletions
diff --git a/doc/src/guide/cookies.asciidoc b/doc/src/guide/cookies.asciidoc
index 33a1940..4825031 100644
--- a/doc/src/guide/cookies.asciidoc
+++ b/doc/src/guide/cookies.asciidoc
@@ -33,24 +33,21 @@ update the expiration time and avoid losing a cookie.
=== Setting cookies
-// @todo So I am not particularly happy about set_resp_cookie/4
-// having Opts as a *third* argument, instead of the *last* like
-// all other functions that come with an Opts argument. We will
-// probably need to change this before 2.0.
-
By default cookies are defined for the duration of the session:
[source,erlang]
+----
SessionID = generate_session_id(),
Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID, Req0).
+----
They can also be set for a duration in seconds:
[source,erlang]
----
SessionID = generate_session_id(),
-Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID,
- #{max_age => 3600}, Req0).
+Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID, Req0,
+ #{max_age => 3600}).
----
To delete cookies, set `max_age` to 0:
@@ -58,8 +55,8 @@ To delete cookies, set `max_age` to 0:
[source,erlang]
----
SessionID = generate_session_id(),
-Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID,
- #{max_age => 0}, Req0).
+Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID, Req0,
+ #{max_age => 0}).
----
To restrict cookies to a specific domain and path, the options
@@ -67,8 +64,8 @@ of the same name can be used:
[source,erlang]
----
-Req = cowboy_req:set_resp_cookie(<<"inaccount">>, <<"1">>,
- #{domain => "my.example.org", path => "/account"}, Req0).
+Req = cowboy_req:set_resp_cookie(<<"inaccount">>, <<"1">>, Req0,
+ #{domain => "my.example.org", path => "/account"}).
----
Cookies will be sent with requests to this domain and all
@@ -81,8 +78,8 @@ available over HTTPS):
[source,erlang]
----
SessionID = generate_session_id(),
-Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID,
- #{secure => true}, Req0).
+Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID, Req0,
+ #{secure => true}).
----
To prevent client-side scripts from accessing a cookie:
@@ -90,8 +87,8 @@ To prevent client-side scripts from accessing a cookie:
[source,erlang]
----
SessionID = generate_session_id(),
-Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID,
- #{http_only => true}, Req0).
+Req = cowboy_req:set_resp_cookie(<<"sessionid">>, SessionID, Req0,
+ #{http_only => true}).
----
Cookies may also be set client-side, for example using