attribute

  • English Full name:HyperText Transfer Protocol
  • Full name: Hypertext Transfer Protocol
  • Model: client-server
  • Feature: stateless (any two connections are not related)
  • Work layer: application layer, architecture inTCPAgreement on
  • Version:1.0 1.1 2.0
  • Protocol:http(Plaintext transmission)https

Status code

The 1XX request has been accepted and needs to continue processing

The 2XX request has been successfully received, understood, and accepted by the server

3XX also requires the client to perform further operations, typically redirects

An error occurs on the 4XX client

5XX Errors occur on the server

Common status code

200 The OK request succeeded

301 Moved Permanently migrating Permanently, and the redirected address is returned

304 Not Modified The resource is Not Modified and uses the local cache

400 Bad Request The syntax and parameters of the Request are incorrect and the server does not understand it

401 Unauthorized The current request requires user authentication or is not authenticated

403 Forbidden The server refuses to execute the command

404 Not Found The requested resource was Not Found

405 Method Not Allowed The requested Method is Not Allowed

500 Internal Server Error Indicates an Internal Server Error

502 Bad Gateway The Gateway receives an invalid response from the upstream server

504 Gateway Timeout The request from the Gateway to the upstream server times out

HTTP is different from HTTPS

  • HTTP is plaintext transmission, and HTTPS is encrypted transmission (SSL+HTTP).
  • The port is different. HTTP is 80 and HTTPS is 443
  • HTTPS requires a CA certificate

2.0/1.0/1.1

1.1

  • Keep-alive long connections are enabled by default in HTTP1.1
  • HTTP1.1 supports sending only header information (without any body information) to save bandwidth
  • HTTP1.1 introduces more cache control policies such asETag,If-None-Match

2.0

  • multiplexing
  • Compression of status lines and headers (there is a mapping table that changes frequently used fields to numbers and makes resources smaller)
  • Server push was introduced, which allows the server to push resources to the browser

TCP three-way and four-way handshake

Three-way handshake

  1. The server enters the answering state
  2. Client –> Server. The client enters the synchronous sending state
  3. The server receives and –> client. The server enters the synchronous receiving state
  4. The client receives and –> server. The client enters the connection state
  5. The server receives the message and enters the connection establishment state

Four times to shake hands

  1. Client –> server. The client enters the termination-wait 1 state
  2. The server receives and –> client. The server enters the closed – wait state
  3. Client received, enter termination – wait 2 state
  4. Server –> Client, server enters final – confirm state
  5. The client receives and –> server. The client enters the shutdown countdown state, which lasts for 2 minutes
  6. The server receives the message and enters the closed state
  7. The client2minAfter enteringClosed connection state

The cache

advantages

  1. Reduced Network traffic
  2. Reduce the strain on the server
  3. Improves page loading speed

Strong cache

cache-controlDetermines the value of, and has the following values

  • No-store (no strong cache, no negotiated cache)
  • No-cache (not strong cache)
  • Public,max-age=31566000

Strong cache summary

  1. Check locally for strong caching before requesting the resource
  2. If a strong cache is hit, is it expired? Read cache resources directly without expiration, otherwise negotiate cache or request latest
  3. If there is no strong cache, go negotiation cache or request latest

Negotiate the cache

response header ETagandLast-ModifiedThe value of the decision

  • ETag can be understood as a unique identification of the current content of a resource
  • Last-modified is the last modification time, in seconds

request header

If-none-match (改 为 ETag) if-modified-since (改 为 last-modified)Copy the code

Negotiation Cache Summary

  1. When requesting a resource, the local ETag of the resource is sent to the server for comparison with the latest resource.
  2. If the resource has not changed, 304 is returned and the browser reads the local cache

Since only the Response header has been modified, the size of request 304 is very small

  1. If the resource has changed, return 200, return the latest resource, and record the new tag and modification time

reference

TCP three-way handshake Four-way handshake

Browser cache