To understand HTTP, let’s look at the TCP/IP protocol family.

Concept: TCP/IP is a general term for all types of Internet-related protocol families

  • Application Layer The application layer determines the activities of communication when providing application services to users

    • FTP- File transfer protocol
    • DNS- Domain name system
    • The HTTP protocol
  • Transport layer The transport layer provides data transfer between two computers on a network connection

    • TCP- Transmission control protocol
    • UDP- User datagram protocol
  • Network layer The network layer is used to process the packets that flow over the network. A packet is the smallest unit of data transmitted over a network. What path does this layer specify to get to the other computer and transmit the packet to the other computer

  • The link layer (also known as the data link layer or network interface layer) handles the hardware part of the network that connects to it

Protocols closely related to HTTP: IP, DNS, and TCP

The IP protocol responsible for transport

The IP protocol transmits various data packets to the peer party. To ensure that the packets are transmitted to the peer party, various conditions must be met, among which the IP address and MAC address are the most important

  • IP address Specifies the IP address assigned to a node
  • The MAC address is the fixed address of the NIC

An IP address can be matched with a MAC address. The IP address is changeable, but the MAC address is basically unchanged

The ARP protocol is used to communicate by MAC address

TCP to ensure reliability

To accurately send data to the target, TCP adopts the three-way handshake policy

  • The sender first sends a packet with the SYN flag to the peer
  • After receiving the packet, the receiving end sends a packet with the SYN/ACK flag to confirm the packet
  • Finally, the sender is sending back a tapeACKFlag to indicate the end of the handshake

DNS service responsible for domain name resolution

Provides domain name resolution services to IP addresses

The relationship between various protocols and THE HTTP protocol

The HTTP protocol

HyperText Transfer Protocol (HTPP) is a HyperText Transfer Protocol used for communication between clients and servers through exchange of requests and responses

HTTP is stateless

HTTP is a stateless protocol that does not itself store the state of communication between requests and responses. Advantages: Faster processing of a large number of things, ensuring protocol scalability, reducing server CPU and memory resource consumption Disadvantages: unable to process the previous state. For example, login state, the solution is to use cookies for state management

Use cookies for state management

The Cookie notifies the client to save the Cookie based on the set-cookie header field in the response packet sent from the server. When the client sends a request to the server next time, the client automatically adds the Cookie value to the request packet and sends the request packet. After discovering the Cookie sent by the client, the server will check which client sent the connection request, and then compare the records on the server to obtain the previous status information

Persistent linking/pipelining

In the original version of the HTTP protocol, TCP connections were disconnected for every HTTP communication. Therefore, when a large number of resources are requested, unnecessary TCP connections are established and disconnected, increasing the communication overhead. To solve the problem of TCP connections, the keep-alive method was developed, which is characterized by keeping TCP connections as long as either end does not explicitly request disconnection (in HTTP/1.1, all connections are persistent by default).

Persistent connections also make it possible to pipe-send the next request without waiting for a response, making it possible to send multiple requests simultaneously in parallel.

HTTP request methods

HTTP1.0 defines three request methods: GET, POST, and HEAD.

HTTP1.1 adds six new request methods: OPTIONS, PUT, PATCH, DELETE, TRACE, and CONNECT.

The serial number methods describe
1 GET Requests the specified page information and returns the entity body
2 HEAD Similar to a GET request, except that there is no concrete content in the response returned, which is used to retrieve the header
3 POST Submit data to a specified resource for processing requests (such as submitting a form or uploading a file). The data is contained in the request body. POST requests may result in the creation of new resources and/or the modification of existing resources
4 PUT Data transferred from the client to the server replaces the contents of the specified document
5 DELETE Asks the server to delete the specified page
6 CONNECT Reserved in HTTP/1.1 for proxy servers that can pipe connections
7 OPTIONS Allows clients to view server performance
8 TRACE The command output displays the requests received by the server for testing or diagnosis
9 PATCH Is a complement to the PUT method and is used to perform local updates on known resources

The HTTP status code

category The reason the phrase
1XX Informational(Informational status code) The received request is being processed
2XX Success(Success Status code) The request is successfully processed
3XX Redirection(Redirection status code) Additional action is required to complete the request
4XX Client Error(Client Error status code) The server cannot process the request
5XX Server Error(Server Error status code) The server failed to process the request

2 xx success

  • 200 OK: Indicates that the request from the client is processed on the server
  • 204 No Content Indicates that the server has successfully processed the request, but the response packet returned does not contain the body of the entity. Generally, it is used when only information needs to be sent from the client to the server, but no new information content needs to be sent to the client
  • 206 Partial Content Indicates that the client made a scoped request and the server successfully executed the Partial GET request

3 xx redirection

  • 301 Moved Permanently redirects Permanently, indicating that the requested resource has been assigned a new URI. The URI indicated by the resource should be used in the future
  • 302 Found Temporary redirection: The requested resource has been assigned a new URI and is expected to be accessed using the new URI this time. Not permanently moved, but temporary in nature
  • 303 See Other Indicates that the resource corresponding to the request has another URI. You need to use the GET method to obtain the requested resource
  • 304 Not ModifiedWhen the client sends a request with conditions attached, the server allows the request to access the resource, but returns the request directly because the request does not meet the conditions304 Not Modified(The server side resource is Not changed, so the client side cache can be used directly)
  • 307 Temporary Redirect Temporary redirection that complies with browser standards and does not change from POST to GET

4XX Client error

  • 400 Bad Request Indicates that an error cannot be detected in the Request packet. You need to modify the Request content and send the Request again
  • 401 Unauthorized Indicates that the request to be sent requires HTTP authentication (BASIC authentication and DIGEST authentication)
  • 403 Forbidden Forbidden Access to the requested resource is denied by the server (for example, access authorization from the file system is not obtained)
  • 404 Not Found The requested resource could Not be Found on the server
  • 405 Method Not Allowed Methods in client requests are prohibited

5XX Server error

  • 500 Internal Server Error Indicates that an Error occurs when the Server executes the request, which may be a bug or temporary fault of the Web application
  • 501 Not Implemented The request was Not supported by the server
  • 502 Bad Gateway Indicates that the server working as a Gateway or proxy receives an invalid response from the remote server when it tries to execute the request
  • 503 Service Unavailable Indicates that the server is temporarily overloaded or undergoing maintenance downtime and cannot process requests
  • 504 Gateway time-out Indicates that the server acting as a Gateway or proxy fails to obtain requests from the remote server in a timely manner
  • 505 HTTP Version Not Supported Indicates that the server does not support the HTTP Version and cannot process the request

In this paper, the source

HTTP- Author: Ueno; Translator: Yu Junliang