HTTP

29 Jul 2022 . network .

  • Connection-Less

    Only one request per one connection

  • StateLess

    The protocol has no memory of transaction, and the server does not know what state the client is.

    Two ways to maintain HTTP connection:

    1. Cookies record the status on the client, such as the login status.
    2. Session records the status on the server.
      Cookie Session
    Definition Cookies are client-side files that are stored on a local computer and contain user information. Sessions are server-side files that store user information.
    Expiry Cookies expire after the user specified lifetime. The session ends when the user closes the browser or logs out of the program.
    Data storage It can only store a limited amount of data. It is able to store an unlimited amount of information.
    Function It is not necessary for us to execute a function in order to get cookies going because they are stored on the local computer. Utilizing the session start() method is required before we can begin the session.
    Data Format Cookies are used to store information in a text file. The data is saved in an encrypted format during sessions.

Status Code

  1. Informational

    100 - Continue

  2. Success

    200 - OK

    201 - Created

    204 - No Content

  3. Redirection

    301 - Moved Permanently

    304 - Not Modified

  4. Client Error

    400 - Bad Request

    401 - Unauthorized

    403 - Forbidden

    404 - Not Found

  5. Server Error

    500 - Internal Server Error

    502 - Bad Gateway

HTTP Request Methods

  • GET requests the specified page information.
  • POST submits data (such as submitting forms or uploading files). The data is included in the request body.
  • PUT replaces the content of the specified document.
  • DELETE deletes the specified page.

GET VS POST

  • GET is used to retrieve remote data and POST is used to insert/update remote data.
  • GET encodes parameters in url (not safe) and POST includes data in body.
  • GET sends once, POST sends header first (return 100) and sends real data (return 200).

Persistent Connection

  • In non-Keep-Alive mode, for each request/response, customer and the server need to create a new connection and disconnect immediately after completion.
  • In Keep-Alive mode, the Keep-Alive function keeps the connection between the client and the server. When there is a follow-up request to the server, the Keep-Alive function avoids establishing or re-establishing the connection.

Breakpoint Continuation

Use HTTP header Range and Content-Range:

  1. The client downloaded a 1024K file, of which 512K has been downloaded.
  2. The network is interrupted, and the client requests to continue. The fragment needs to be continued declared in the HTTP header: Range:bytes=512000-, which informs the server to transfer files from the 512K location of the file.
  3. The server receives a breakpoint continuation request, starts from the 512K position of the file, and adds it to the HTTP header: Content-Range:bytes 512000-/1024000, and the HTTP status code returned by the server should be 206.