LOGBOOK

HELP

1 / 22
Other keys: showSpace: good1-4: rate0: skip5: flag

Question

Why is HTTP called a "stateless" protocol?

Answer

Each HTTP request is independent and self-contained, so the server keeps no memory of previous requests.

After sending a response, the server has no memory of the client. Each request-response cycle is complete in itself. This means the server can't naturally track:

  • Which user is making requests
  • What they did in previous requests
  • Shopping cart contents, login status, etc.

Cookies and sessions were invented to work around this limitation.

or press any other key

Question

What are cookies and how do they work?

Answer

Cookies are key-value pairs the browser stores and automatically resends with every request to the same domain.

How they work:

  1. Server sets a cookie via Set-Cookie header in response
  2. Browser stores the cookie
  3. Browser sends cookie with every subsequent request to that domain
  4. Server can read the cookie values

Cookies persist across requests and browser sessions (until they expire), enabling stateful behavior over stateless HTTP.

Go deeper:

A possible interaction between a web browser and a web server holding a web page in which the server sends a cookie to the browser and the browser sends it back when requesting another page
A possible interaction between a web browser and a web server holding a web page in which the server sends a cookie to the browser and the browser sends it back when requesting another page
Tizio · CC BY-SA 3.0 · Wikimedia Commons
or press any other key