Skip to content

Commit 494bdd7

Browse files
committed
Add note about Ring sessions to README caveats
Fixes #18.
1 parent ddedc30 commit 494bdd7

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,29 @@ third-party strategies already exist:
156156
## Caveats
157157

158158
This middleware will prevent all HTTP methods except for GET and HEAD
159-
from accessing your handler without a valid anti-forgery token.
159+
from accessing your handler without a valid anti-forgery token, or a
160+
custom header if the `:safe-header` option is set.
160161

161162
You should therefore only apply this middleware to the parts of your
162163
application designed to be accessed through a web browser. This
163-
middleware should not be applied to handlers that define web services.
164+
middleware should not be applied to handlers that define web services
165+
intended for access outside of the browser.
166+
167+
Also note that the default session strategy modifies the session. As
168+
with all Ring applications, care should be taken not to override the
169+
request session:
170+
171+
```clojure
172+
;; This will overwrite all existing values in the session
173+
(defn bad-handler [_request]
174+
{:status 200, :headers {}, :body "foo = 1"
175+
:session {:foo 1}})
176+
177+
;; This will only update the :foo key in the session
178+
(defn good-handler [{:keys [session]}]
179+
{:status 200, :headers {}, :body "foo = 1"
180+
:session (assoc session :foo 1)})
181+
```
164182

165183
## License
166184

0 commit comments

Comments
 (0)