Make a summary every day, persistence is victory!

/** @date 2021-06-25 @description 图 文 HTTP - Chapter 2 - Simple HTTP protocol */Copy the code

One (based on HTTP/1.1)

  1. HTTPUsed on both client and server sidescommunication, the party requesting access to resources such as text or image is called the client, and the one providing resource response is called the server. In the process of applying HTTP protocol to communication,Must beThere is a client side and a server side
  2. HTTP communicates through an exchange of requests and responses, the clientSend the request first, server sideTo respond toRequest and return the appropriate resource
  3. The request message is sent byRequest method.The request URI, protocol version, optional request header field and entity content

4. The response packet consists of the protocol version, status code, reason field used to explain the status code, optional response header field, and entity body

5. HTTP isstatelessProtocol. HTTP itself does not save the communication status before the request and response. When using HTTP, a new request will be generated every timefasterHandle a large number of transactions to ensure protocolscalabilityDeliberately designed to be so simple; In order to implement the stay-state function, introducedCookie6. HTTP uses THE URI to locate network resources. Therefore, the URI must be added to the request packet for accessing resourcesThe request URI7. Inform the server of the intentHTTP method

A. GET: used to request access to a resource that has been located by the URI, and the corresponding resource is processed by the server and returns a response b. POST: Used to transmit the entity body (GET can also transmit the entity body, but POST is generally used because of security and request restrictions) C. PUT: The HTTP/1.1 PUT method does not have a validation mechanism, so there are security issues. It is usually used for Web applications or similar websites that use REST standards. PUT d. HEAD: E. DELETE: deletes a file. Like PUT, HTTP/1.1 DELETE does not provide authentication. F. OPTIONS: Method for querying support for the resource specified against the request URI G. TRACE: method for the server to loop back previous request traffic to the client H. CONNECT: CONNECT requires that a tunnel be established when the proxy server communicates with each other to realize communication with the tunnel protocol. Secure Sockets Layer (SSL) and Transport Layer Security (TLS) are used to encrypt communications and transmit them through network tunnelsCopy the code
  1. The above method command is used when sending request packets to the resource specified by the request URI. The function is to specify the requested resource as expectedProduce certain behavior

9. Persistent connections and pipework

Persistent connection:

In the original version of HTTP, TCP connections were disconnected every time HTTP communication was made. In the case of a large number of requests, this was a performance drain. So HTTP/1.1 and parts of HTTP/1.0 proposed persistent connections. Keep TCP connections persistent connections reduce repeated TCP disconnections and connections, reduce extra overhead, and make the page display faster. All connections in HTTP/1.1 are persistent by defaultCopy the code

pipelines:

Instead of waiting for the last request to complete before sending the next request, pipework can send the next request directly without waiting for the response of the previous requestCopy the code

Use 10.CookieState Management

HTTP is a stateless protocol, the advantage is that there is no need to save the state, which can reduce the server memory and CPU consumption. However, when the state needs to be saved, additional parameters must be added to the request message each time to manage the state, so cookies are introduced. Manage state by writing cookies in request and response packets. The client saves cookies based on set-cookie in the header field of the response packet returned by the server. In addition, Cookie is automatically added into the request message every time the server sends a request to the server. After receiving the Cookie sent by the client, the server will check which client it is sent from, and then compare the records on the server to get the previous status informationCopy the code