HTTP and HTTPS

  1. HTTP plaintext transmission, data is not encrypted, poor security. HTTPS is an HTTP protocol based on SSL and TLS. It can be used for encrypted transmission and identity authentication.
  2. The connection mode and port are different. HTTP is 80, HTTPS is 443.
  3. HTTPS requires a CA certificate, so it also costs some money.

Url request to page display

It can be divided into three stages:

HTTP request phase

  1. Browser parsing URL
  2. toThe DNS serverThe domain name resolution request is sent
    • The browser first checks to see if it has an IP address for the resolved domain name in its cache. If so, end it. If not,
    • The operating system will continue to check for parsed results.
    • If not, the local domain name server (LDNS) is asked to resolve the domain name.
    • If not, go to root server => eventually to the domain name server registered for the site.
    • Once found, the destination IP address is returned to the LDNS. After being cached by the LDNS, the IP address is returned to the user and cached in the local system. Finally finish parsing.
  3. Establish a TCP/IP connection with the IP address corresponding to domain name resolution
    • Cookie and Session: Cookies are stored in the client browser, and sessions are stored in the server.
  4. Sending HTTPThe request messageRequest to get the page.
    • Host | referer | user-agent | accept | Connection | Accept-Language | …

HTTP response phase

  1. The serverThe response message
    • Cache-Control | Content-Encoding | date | etag | expries | last-modified | …
  2. The page where the client receives the response from the server

Browser render phase

  1. The browser allocates a stack of memory and starts executing code
  2. When static resources such as JS, CSS, images are encountered, a new process is created to load, and the main process continues to execute the code. However, when external JS is encountered, HTML parsing will stop and continue parsing HTML after JS execution is complete. Prevents JS from modifying the already completed DOM tree.
  3. Parsing the HTML from top to bottom generates a DOM tree
  4. After the style resource is loaded, the cssOM (CSS object model) tree is generated
  5. The cssOM tree is combined with the DOM tree to create a render tree.
  6. Once the render tree is built, the browser calculates the size and absolute position of the element.
  7. After the layout calculation is complete, the browser renders the page elements, which are processed by the rendering engine, and the entire page number is displayed.

TCP’s three handshakes and four waves

TCP (Transmission Control Protocol).

URG Whether the emergency pointer is valid. The value is 1, indicating that one of the packets needs to be processed first
ACK Check whether the check number is valid. Generally, set it to 1.
PSH Prompts the receiving application to immediately read the data from the TCP buffer.
RST The other party asked to re-establish the connection, reset.
SYN Request to establish a connection and initialize the serial number in its serial number field. Set the connection to 1
FIN Wish to disconnect

Three-way handshake

  1. On the first handshake, a connection is established, the client sends a SYN (synchronous sequence number) (SYN = X) packet to the server and enters the SYN_SENT state, waiting for the server to confirm.
  2. On the second handshake, the server receives a SYN packet and must acknowledge the client’s SYN (ACK = X + 1) and send its own SYN packet. At this time, the server enters the SYN_RECV state.
  3. On the third handshake, the client receives the SYN + ACK packet from the server and sends an ACK packet (ACK = Y + 1) to the server. After the ack packet is sent, the client and the server enter the ESTABLISHED state. Complete three handshakes.

Four times to wave

  1. First wave: The client process sends a connection release packet and stops sending data. Release the data header, FIN (wish to disconnect) =1, and the serial number is SEq = U. The client enters the FIN_WAIT_1 state.
  2. Second wave: After receiving the connection release packet, the server sends an acknowledgement packet, ACK (whether the acknowledgement number is valid or not, usually set to 1) =1, ACK = U +1, and carries its serial number seq= V. At this point, the server enters close-wait state. After receiving the confirmation request from the server, the client enters the FIN-WaIT-2 state and waits for the server to send a connection release packet.
  3. Third wave: After sending the LAST data, the server sends a connection release packet with FIN=1 and ACK = U +1 to the client. The server is probably in the semi-closed state. Assume that the serial number is SEQ = W, then the server enters the last-ACK state and waits for the client’s confirmation.
  4. Fourth wave: After receiving the connection release packet from the server, the client sends ACK=1, ACK= w+1 and its serial number is SEq = U +1. In this case, the client enters the time-wait state. Note that the TCP connection is not released at this time. The client enters the CLOSED state only after revoking the corresponding TCB. The server enters the CLOSED state immediately after receiving an acknowledgement from the client. Similarly, revoking the TCB terminates the TCP connection. As you can see, the server ends the TCP connection earlier than the client.