# Q7(b) · HTTP cookies

Subject: Computer Networks

Exam: TEE

Reader: https://deep-learning-study-room.vercel.app/cn/#tee/papers/paper-2022-ai-final/q7b

Canonical: https://deep-learning-study-room.vercel.app/read/cn/tee/papers/paper-2022-ai-final--q7b/

Exact historical variant. Current-syllabus questions solved; excluded topics and source limitations stated.

### Q7(b). An e-commerce site wants to keep a purchase record for each customer. Illustrate how cookies can do this. [5 marks]

### Answer

| Concept | Explanation | Example |
| --- | --- | --- |
| GET | Retrieve the selected representation | Read a page |
| POST | Ask the resource to process submitted content | Submit a form |
| PUT / DELETE | Replace target representation / request removal according to server semantics | Update/delete an API resource |
| 200 / 301 / 404 / 500 | Success / permanent redirect / not found / server error | Read status before interpreting body |
| Persistent connection | Reuse a connection for multiple exchanges | Avoid repeated TCP setup for each image |
| Cookie/session token | Carry an identifier so the application can relate requests | Remain signed in |
| HTTPS | HTTP protected by authenticated encryption through TLS in common deployments | Protect credentials and content in transit |

A secure transport protects the connection; it does not prove that every server’s content is truthful. HTTP method semantics and application authorization still matter. For exam comparisons, separate HTTP semantics, connection lifetime and application session state.

#### Practical example

A login page may send a session cookie after successful authentication. Later requests include it even though each HTTP request remains a separate protocol exchange.

|  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| **First visit** | → | **Server creates customer/session ID** | → | **Set-Cookie header** | → | **Browser stores cookie** | → | **Later Cookie header** | → | **Server retrieves purchase record** |

Keep the purchase record in the server database keyed by a suitable identifier; the browser need only carry that identifier. Example: cookie customer=R81 links later visits to R81’s stored orders. HTTP requests remain independent at the protocol level; the application supplies continuity. Account login can restore the record when a cookie is absent.
