HTTP1. X and 2.0

Source: Internet
Author: User
Tags ack format definition http 2

Httphttp 1.X
    1. HTTP is built on the TCP protocol, and the Bottleneck and optimization of HTTP protocol are based on the characteristics of TCP protocol itself.

    2. When TCP establishes a connection, there are three handshakes that have a 1.5RTT delay, in order to avoid the delay in which each request undergoes a handshake, the application layer chooses an HTTP long connection of different policies.

The HTTP 1.0 connection is not reusable and has head of line blocking problem.
http1.0协议头里可以设置Connection:Keep-Alive。在header里设置Keep-Alive可以在一定时间内复用连接,具体复用时间的长短可以由服务器控制,一般在15s左右。到http1.1之后Connection的默认值就是Keep-Alive,如果要关闭连接复用需要显式的设置Connection:Close。<br />head of line blocking会因为一个request没有到达服务器或者一个response因为网络没有及时返回而影响后续所有请求。
Connection multiplexing issues TCP Long link HTTP long-polling

The client sends a polling request to the server in its initial state, and the server does not return the business data immediately, but waits for the new business data to be returned when it is generated. So the connection will be kept, and once it is over, a new polling request will be launched again and again.

HTTP Streaming

Unlike long-polling, the server does not end the initial streaming request, but continues to return the latest business data through this channel, but this channel is one-way.

Web socket

Similar to the traditional TCP socket connection, it is based on the TCP protocol and provides a bidirectional data channel.

Resolve head of line blockinghttp pipelining

Instead of waiting for the response of other requests to return, each request is sent to the server almost at the same time.

SPDY

HTTP 1.X has many problems, after experimenting with various optimization methods proposed by the SPDY scheme.

Spdy Target
    • Reduce latency, the client's single-connection single request, and the server's FIFO response queue are the big heads of the delay.
    • HTTP was originally designed to be a client-initiated request, and then the server responded that the server could not actively push content to the client.
    • The header of the compressed HTTP header,http1.x is becoming more and more expansive, and the cookie and user agent can easily increase the size of the header to 1kb or more. And because of the stateless nature of HTTP, the header must be carried repeatedly every request, a waste of traffic.
Spdy Basic Functions
    • Multiplexing. Multiplexing uses multiple request streams to share a TCP connection, resolving the issue of the HTTP 1.x hold of the line blocking, reducing latency while increasing bandwidth utilization.
    • The request priority level. Multiplexing poses a new problem that can cause some critical requests to be blocked on the basis of connection Sharing.
    • Header compression. HTTP1. The header of X is often redundant. Choosing the appropriate compression algorithm can reduce the size and number of packets.
Spdy Advanced Features
    • Server Push. Http1.x can only be initiated by the client, and then the server sends the response passively. After the server push is turned on, the server pushes it by X-Associated-Content header informing the client that new content will be available.
    • Server hints. Unlike server push, the server hint does not actively push content, just to tell them that new content is being generated, and that the content is downloaded or that the client initiates the request. Server hint through X-Subresources header to notify.
HTTP 2.0
    • The basic mode of the client sending request to the server does not change.
    • The old scheme does not change, http://和https:// and the services and apps that are used do not have to make any changes.
    • Clients and servers using http1.x can be transferred seamlessly to http2.0 on a proxy basis
    • Proxy servers that do not recognize http2.0 can downgrade requests to http1.x
HTTP 2.0 major changes to the new binary format

HTTP 1.x is a plaintext protocol, formatted by strat line , header and composed of body . Need to do protocol parsing to identify these 3 parts, http1.x parsing is based on text, and text format parsing has a natural flaw, binary is more convenient and robust than text format.


The format definition for HTTP 2.0 is closer to TCP. Consists of,,, Length Type Flags Stream ID , Payload 5 parts.

    • lengthDefines the start to end of the entire frame
    • typeDefine the type of frame
    • flagsSome important parameters are defined with bit bits.
    • stream idUsed as flow control
    • payloadis the body of the request
Connection Sharing

stream idThe function is the Connection Sharing mechanism, a request corresponds to a stream and assigns an ID, so that a connection can have more than one stream, each stream frame randomly mixed together, the receiver according to the stream The ID will then attribute the frame to its different request. Each stream can have priority and dependency set.

Header compression

HTTP2.0 uses encoder to reduce the size of headers that need to be transferred, each of the two parties caches a header fields table to avoid repeating header transfers and reducing the transfer size.

Compression algorithm Selection

SPDY/2 uses the gzip compression algorithm, later appearing BREACH and CRIME 2 kinds of attack methods, even if the SPDY to go SSL can also crack the content, http2.0 adopt HPACK the compression algorithm.

Reset Connection Performance

For HTTP 1.x, it is by setting the reset flag in the TCP segment to notify the peer to close the connection. Http2.0 introduces a RST_STREAM type of frame that cancels the stream of a request on a continuous connection basis.

Flow control

Http2.0 by a similar receive window approach, the recipient of the data flow window shows how much data they can receive by telling their own size. Only the data type of frame has the flow control function.

Service push

Http2.0 pushes the content of the client's requirements forward to the past, also called cache push . If the client exits, it needs to server push be canceled and can be done by sending RST_STREAM the type of frame.

Nagle algorithm/tcp Delayed Ack

Nagle Algorithm/TCP Delayed Ackis a set of opposing algorithms. http2.0 can be TCP_NODELAY disabled by disabling Nagle or by TCP_QUICKACK disabling ACK. Official recommended settingsTCP_NODELAY

More secure SSL

HTTP2.0 used the expansion of TLS ALPN to do protocol upgrades, in addition to the encryption of this piece has a change, HTTP2.0 to TLS security to do a step closer to strengthen

HTTP1. X and 2.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.