Alex's Notes

Kumar Chapter 04: HTTP

Metadata

  • Title: Hypertext Transfer Protocol (HTTP)

  • Number: 4

  • Book: Kumar, Akshi, Web Technology: Theory and Practice

Core Ideas

HTTP uses the request/response paradigm.

HTTP is a pull protocol. The client pulls information from the server (instead of the server pushing info to the client).

HTTP is stateless. Each request-response exchange is treated independently. Clients and servers are not required to retain state. An HTTP transaction consists of a single request from client to server, and a single resopnse from server to client. To maintain state, a website must rely on proxies and cookies.

HTTP is media independent. Any type of data can be sent via HTTP. Both client and server specify content type using MIME types.

Unlike HTTP/1.0 HTTP/1.1 supports persistent connections, once the TCP handshake is made, the connection is kept alive and multiple requests and responses between client and server can be made over the same connection.

The phases of the communication are:

  1. Handshaking - opens the TCP connection.

  2. Client request - Once the connection is established, the client sends the request formatted according to the rules of the standard.

  3. Server response - server interprets the request and sends a response.

  4. Close (optional) - closes the connection.

Every request has this structure:

headers take the form: <key>: <value>

Every response has this structure:

Here’s an example:

State Retention: Cookies

Cookies are an application-based solution to provide state retention over a stateless protocol. They are small bits of info that are sent in response from the server to the client. They are then stored on the client’s device.

A cookies is a key-value pair, with a lifespan that can be set by the server. It’s provided by the server as a response header, stored by teh client and then returned to the server as a request header.

A simple cookie can be set with this header: Set-Cookie: <cookie-name>=<cookie-value>

The chapter includes some material on caching, but it’s very thin and a bit outdated.