Cookies and flash messages
Managing context on the browser.
Managing context on the browser.
Each request is processed independently by the server with no memory of previous requests, so clients must resend all context every time.
Our web applications need continuity between requests, they need some state to be stored in the browser.
Cookies are a mechanism for passing name, value pairs to the browser via a header.

| |
The browser will store the data and send it back in every request under the given
path.
A cookie header will be included with every subsequent request.

| |
This allows the browser to maintain state.
We can delete a cookie from the browser by sending another header.

| |
In this way, our server can control the browser cookie state. Although users can clear their cookies.
To harden up our security, we should set some options.

| |
In development, we are serving over plain HTTP so we can’t use
securecookies.
Cookies are somewhat limited because they have a specific format.

| |
Encoding data allows us to add arbitrary messages into cookies.
When we redirect, we can optionally pass a flash message to the browser

| |
The message will be passed back as a cookie in the next response.
When we render an HTML response, we can include (and delete) the flash message.

| |
If there is no message, nothing is included.
If you have any questions, now is a good time to ask.
Thanks for listening