[Notes] [HTTP] "Graphic HTTP" Chapter 2 Simple HTTP Protocol

foreword

  • Where there is input, there must be output. This note is a summary of the knowledge involved in each chapter after I read "Graphic HTTP"
  • The blog will publish each chapter of the book as an article, and the next blog will be published at an uncertain time
  • Some of the notes in the notes have been sorted out after personal understanding, and there may be deviations. Readers are also kindly requested to help point out, thank you.

disclaimer

  • This blog is my notes after studying "Graphic HTTP", which is intended to facilitate review and review, not for commercial purposes.
  • For the sake of convenience, some pictures on the blog are consistent with those in the book, so I didn’t take screenshots by myself, but quoted the picture addresses of other people’s blogs, and thanked these bloggers for their picture beds.
  • This note is used to record my summary of this knowledge. To facilitate future work and study.
  • The content is not complete with the original book, please read it in conjunction with the original book
  • If there is any infringement, please inform and delete it immediately.

Chapter 2 Simple HTTP Protocol

2.1 HTTP is used for communication between client and server

1. Detailed explanation of HTTP protocol

  • For communication between client and server

    • Client : The end that requests access to resources such as text or images.
    • Server : the end that provides access to resources
  • When using the HTTP protocol to communicate between two computers, one end of a communication line must be a client, and the other end must be a server

  • The request must be made by the client , and the server returns a response .

  • is a stateless protocol

    • no status:
      • don't save state
        • The HTTP protocol itself does not save the communication state between the request and the response (that is, the protocol does not persist the sent request or response.)
        • Whenever a new request is sent, a corresponding new response will be generated.
        • The message information of all previous requests or responses is not retained .
      • Purpose: Process large numbers of transactions faster.
      • Advantages: It can reduce the consumption of CPU and memory resources of the server.
  • Although it is a stateless protocol, in order to achieve the desired state-keeping function, Cookie technology is introduced .


2. Request message

  • Request message composition

    field Indicates the description
    [Method](# 5. HTTP method to inform the server of intent) The type of server requesting access
    [URI](# 4. Request URI to locate resources) Indicates the resource object to request access to
    protocol version Prompt the client to use the HTTP protocol function
    request header field
    content entity

3. Response message

  • Response message composition

    field Indicates the description
    protocol version The HTTP version corresponding to the server
    status code The status code of the processing result of the request
    Reason Phrase for Status Code
    response header field Each attribute of the header field (response date and time)
    main body resource entity

4. Request URI to locate resource

  • The HTTP protocol uses URIs to locate resources on the Internet.
    • [Reason] One of the URI functions: resources anywhere on the Internet can be accessed.
  • Request URI method
    1. full request URI
    2. Write the network domain name or IP address in the first field Host
    3. If you are not accessing a specific resource but making a request to the server itself, you can *replace the request URI with a

5. HTTP method to inform the server of intent

method name effect
GET Used to request a resource identified by a URI
POST The principal used to transfer the entity
PUT used to transfer files
HEAD It is used to confirm the validity of the URI and the date and time of the natural update (that is, to obtain the header of the message )
DELETE Used to delete files (generally do not use this method)
OPTIONS The method used to query the resource support specified for the request URI
TRACE Let the web server loop back the previous request communication to the client (not commonly used, easy to deal with XST cross-site tracking attacks)
CONNECT It is required to establish a tunnel in the proxy server communication to realize TCP communication with the tunnel protocol

2.7 Persistent connections save traffic

  • [Problems in communication] - Every time HTTP communication is performed, a TCP connection must be disconnected

    • When a large number of resources are loaded with requests, each request will cause insignificant TCP connection establishment and disconnection, increasing the overhead of communication traffic

  • 【How to solve】

1. Persistent connection

  • Features: As long as either end does not explicitly propose to disconnect , the TCP connection state will be maintained.

    • Implementation: After establishing a TCP connection, perform multiple request and response interactions.

  • benefit:

    1. Reduce the overhead caused by repeated establishment and disconnection of TCP connections
    2. Reduced load on the server side
    3. The web page display speed is correspondingly improved.

2. Pipelining

  • Send multiple requests in parallel at the same time without waiting for responses one after another

  • Faster than persistent connection technology.


2.8 State management using cookies

  • Technical implementation: Control the status of the client by writing Cookie information in the request and response messages .

  • Use cookies to save state process:

    [External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-19zFq838-1683595659183)(https://cache.yisu.com/upload/information/20200310/57/118906 .jpg)]

    1. The cookie will notify the client to save the cookie according to a header field information called Set-Cookie in the response message sent from the server .
    2. When the client sends a request to the server next time, the client will automatically add the Cookie value in the request message and send it out.
    3. After the server finds the cookie sent by the client, it will check which client sent the connection request, then compare the records on the server, and finally get the previous status information.

Guess you like

Origin blog.csdn.net/weixin_45944495/article/details/130572918