• 1. Introduction

    • methods
  • 2. Bottlenecks and disadvantages

    • disadvantages

    • bottleneck

  • 3. Version differences

    • keywords

    • The difference between 1.1 and 1.0 and

    • SPDY: optimization of http1.x

    • Differences between 2.0 and SPDY

    • The difference between 2.0 and 1.x

  • 4. A status code

    • category

    • Abstract

  • WebSocket

    • Whether HTTP2 can replace WebSocket
  • 5. Refer to the article

1. Introduction

Port 80, application layer protocol

methods

  • GET: Obtains resources
  • POST: transmits the entity body
  • PUT: transfers files
  • HEAD: obtains the packet HEAD
  • DELETE: deletes a file
  • OPTIONS: Asks for supported methods
  • TRACE: indicates a tracing path
  • CONNECT: Requires a tunnel protocol link proxy (using SSL Secure Sockets Layer, or TLS Transport Layer Security)

A persistent connection saves traffic. HTTP keep-alive or Connection reuse remains TCP as long as either party does not explicitly propose to disconnect

2. Bottlenecks and disadvantages

disadvantages

  • Plaintext transmission (easy to eavesdrop)
  • Lack of service authentication (vulnerable to man-in-the-middle attacks)
  • Lack of integrity verification (easy to tamper with)

bottleneck

  • Unsaved state
  • Only one request can be sent on a connection
  • Requests can only be developed from the client, and the client cannot receive instructions other than responses
  • The request and response headers are sent without compression. The more headers, the longer the delay
  • Send lengthy headers. Sending the same headers each time causes more waste
  • You can choose any data compression format. Uncompressed send

3. Version differences

The differences between HTTP1.0, HTTP1.1, and HTTP2.0

There are two main factors that affect an HTTP network request: bandwidth and latency.

Bandwidth: If we were still in the dial-up phase, bandwidth would be a serious problem, but now that the network infrastructure has improved bandwidth so much that we don’t have to worry about bandwidth affecting speed, all that’s left is latency.

Delay:

  • HOL blocking: Browsers block requests for a number of reasons. A browser can have only four connections for the same domain name at a time (this may vary depending on the browser kernel). If the number of connections exceeds the threshold, subsequent requests will be blocked.

  • DNS Lookup: The browser needs to know the IP address of the target server to establish a connection. The system that resolves domain names into IP addresses is called DNS. This can often be done with DNS caching results to reduce this time.

  • Initial Connection: HTTP is based on TCP. The browser can set up an actual connection only after the third handshake. However, these connections cannot be reused, resulting in three handshakes and slow startup for each request. The effect of three-way handshake is more obvious in the case of high latency, and the effect of slow startup is more significant in the case of large file requests.

The difference between 1.1 and 1.0 and

keywords

  • host
  • Connection: keep-alive
  • range

  • HTTP1.0 mainly uses if-modified-since,Expires in headers. HTTP1.1 introduces more cache control policies such as Entity tag, If-unmodified-since, if-match, if-none-match, etc.

  • HTTP1.0, there is some waste of bandwidth, such as the client only needs a part of an object, and the server will send the whole object over, and does not support resumable breakpoint function, HTTP1.1 is introduced in the request header range header field, which allows only a part of the resource request, The return code is 206 (Partial Content), which makes it easy for developers to make the most of bandwidth and connections.

  • Error notification management add 24 error status response codes in HTTP1.1, such as 409 (Conflict) indicates that the requested resource is in Conflict with the current state of the resource; 410 (Gone) Indicates that a resource on the server is permanently deleted.

  • The Host header processing in HTTP1.0 assumes that each server is bound to a unique IP address, so the URL in the request message does not pass the hostname. However, with the development of virtual hosting technology, there can be multiple virtual hosts (multi-homed Web Servers) on a physical server, and they share the same IP address. HTTP1.1 both Request and response messages should support the Host header field, and an error (400 Bad Request) will be reported if there is no Host header field in the Request message.

  • HTTP 1.1 supports long Connection and Pipelining processing that delivers multiple HTTP requests and responses over a SINGLE TCP connection, reducing the cost and latency of establishing and closing connections. Connection: keep-alive is enabled by default in HTTP1.1, somewhat compensating for the fact that HTTP1.0 creates a Connection on every request.

Pipelining can cause congestion at the head of the team

Queue head blocking means that when one request in the sequential request sequence is blocked for some reason, all the subsequent requests are also blocked, causing the client to fail to receive data.

For queue head blocking:

1. Allocate resources on the same page to different domain names to increase the connection upper limit. Although it is possible to share a TCP pipe, only one request can be processed at a time in a pipe, and other requests can be blocked until the current one is completed. Reduce the number of requests 3. Inline some resources, such as CSS and Base64 images 4. Merge small files to reduce the number of resources

SPDY: optimization of http1.x

SPDY sits below HTTP, on top of TCP and SSL, making it easy to accommodate older versions of HTTP (encapsulating http1.x content into a new frame format) while using existing SSL functionality.

  • For HTTP’s high latency problem, SPDY gracefully takes multiplexing. Multiplexing can share a TCP connection through multiple request streams, which solves the problem of HOL blocking, reduces latency and improves bandwidth utilization.

  • A new problem with multiplexing is that key requests can be blocked on a shared basis. SPDY allows you to prioritize each request so that important requests get a response first. For example, when the browser loads the home page, the HTML content of the home page should be displayed first, and then all kinds of static resource files and script files are loaded, so as to ensure that users can see the content of the web page in the first time.

  • The http1. x header mentioned earlier is often redundant. Choosing the right compression algorithm can reduce the size and number of packets.

  • HTTPS based encryption protocol transmission greatly improves the reliability of transmitted data.

  • Server push adopts SPDY web page. For example, my web page has a style. CSS request. When the client receives style. CSS data, the server will push the style.js file to the client. When the client tries to fetch style.js again, it can fetch it directly from the cache without having to request it again.

Differences between 2.0 and SPDY

  • HTTP2.0 supports plaintext HTTP transport, while SPDY enforces the use of HTTPS
  • The HTTP2.0 header compression algorithm uses HPACK rather than DEFLATE, which is used by SPDY

The difference between 2.0 and 1.x

  • The new Binary Format, http1.x parsing is text-based. There are natural defects in format parsing based on text protocol. There are various forms of text expression, and many scenarios must be considered in order to achieve robustness. Binary is different, only recognizing the combination of 0 and 1. Based on this consideration HTTP2.0 protocol parsing decision to adopt binary format, implementation is convenient and robust.

  • MultiPlexing means that each request is used as a connection sharing mechanism. A request corresponds to an ID. In this way, a connection can have multiple requests. The requests of each connection can be randomly mixed together, and the receiver can assign the requests to different server requests according to the REQUEST ID.

  • HTTP2.0 uses encoder to reduce the size of the headers that need to be transferred. The communication parties cache a table of header fields. This avoids duplicate header transmission and reduces the size of the required transmission.

  • Server push. Like SPDY, HTTP2.0 has server push functionality.

4. A status code

category

  • 1XX: Informational status code (received request being processed)
  • 2XX: Success status code (The request is successfully processed)
  • 3XX: Redirection status code (additional action required to complete the request)
  • 4XX: Client error status code (server cannot process request)
  • 5XX: Server error status code (server processing request error)

Abstract

  • 200 OK. The request is processed normally

  • 204 Not Content The response packet does Not contain notice

  • 206 Partial Content Client made a range request

  • 301 Moved Permanently Redirected Permanently

  • 302 Found: A temporary redirection. The requested resource is assigned a new URI and the user is expected to access it using the new URI

  • 303 See Other

  • 304 Not Modified Indicates that the request packet contains if-match and IF-Modified-since. The packet that returns the 304 status code does Not contain the body part

  • 307 Temporary Redirect Temporary redirection

  • 400 Bad Request Syntax errors exist in the Request packet

  • 401 Unauthorized Authentication information is required for HTTP authentication

  • 403 Forbidden Access to the requested resource is denied

  • 404 Not Found The server could Not find the requested resource

  • 500 Internal Server Error: The Server fails to execute the request

  • 503 Service Unavailable: The server is temporarily overloaded or is down for maintenance and cannot process requests

WebSocket

Whether HTTP 2 can replace WebSocket

  • Will WebSocket survive HTTP/2?

  • HTTP / 2 cannot completely replace HTTP.

  • In the world of HTTP / 2, hacking like domain sharding, resource inlining, and image splicing will backfire.

  • HTTP / 2 does not replace push technologies such as WebSocket or SSE.

  • The HTTP / 2 push server is handled only by the browser, not by the application.

  • The combination of HTTP / 2 and SSE provides efficient HTTP-based two-way communication.

5. Refer to the article

  • The differences between HTTP1.0, HTTP1.1, and HTTP2.0
  • JavaGuid/ Computer network.md
  • HTTP/1, HTTP/2, HTTP/3