This is the fourth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021.

The HTTP protocol

HTTP is an application layer protocol based on TCP. HTTP is often used to access remote network resources on both mobile and PC terminals. The seven layer protocols of the OSI network from top to bottom are the application layer, presentation layer, session layer, transport layer, network layer, data link layer, and physical layer. TCP/IP is layered into the application layer, transport layer, data link layer, and physical layer from top to bottom.

Functions of the HTTP protocol

HTTP stands for Hypertext Transfer Protocol.

  • Specifies the data transfer format between the client and server.
  • Let the client and server can effectively communicate data.

The characteristics of HTTP

No connection, stateless, HTTP persistent connection, Cookie/Session

HTTP statelessness: THE HTTP protocol has no memory for transaction processing.
  • Each request is independent, and its execution and result are not directly related to the Amina request or subsequent request. That is, it is not directly affected by the previous request response condition, nor does it directly affect the subsequent request response condition.
  • The server does not store the state of the client, and the client must bring its state to the server each time.
  • The standard HTTP protocol refers to the HTTP protocol that excludes cookies, sessions, and applications

HTTP is a stateless protocol, and Cookie technology is introduced to preserve state:

  • Cookie Controls client status by writing Cookie information in request and response packets.
  • The server notifies the client to save the Cookie based on the header field of set-cookie in the response packet sent by the server.
  • The next time the client sends a request, it carries a Cookie value so that the server knows who sent the request.
HTTP persistent connections

  • Nonpersistent connections: Each connection handles one request-response transaction.
  • Persistent connections: Each connection can handle multiple request-response transactions (the server sends a response that leaves the TCP connection open, and subsequent requests and responses between the same client/server can be sent through this connection).
  • HTTP/1.0 uses non-persistent connections. HTTP/1.1 uses a persistent Connection by default: keep-alive.
How do HTTP persistent connections determine whether a request has ended?
  • Content-length: Indicates whether the number of received bytes reaches the content-length value.
  • Chunked: transfer-encoding. When block transmission is selected, content-Length may not be included in the response header. The server responds with a message with no data (only the response line and header and \r\n), and then begins transmitting several data blocks. After several data blocks are transferred, an empty data block needs to be transferred. When the client receives the empty data block, the client knows that the data is received.

Why use HTTP

  1. Simple and fast: Because the HTTP protocol is simple, the HTTP server program size is small, so the communication speed is fast.
  2. Flexibility: HTTP allows the transfer of any type of data.
  3. Use very persistent links: limit each link to one request, and the server responds to the client’s request by immediately connecting to the port, saving transmission time.