(iv) Flow of HTTP/2

Source: Internet
Author: User

A "stream" is a separate, bidirectional frame sequence exchanged between the client and the server in a HTTP/2 connection. The stream has several important features:

    • A single HTTP/2 connection can contain multiple simultaneous open streams, and the two endpoints of the stream cross-access frames from multiple streams.
    • Streams can be created and used unilaterally by the client or the server, and can also be shared between the client and the server.
    • The stream can be closed by either end.
    • The order in which frames are sent on the stream is important. The receiving party processes the frames in the order in which they are received. In particular, the order of header and data frames is semantically important.
    • The stream is identified by an integer. The identifier for the stream is assigned by one end of the initialization stream.
The life cycle and state transitions of a stream

The life cycle of the stream is as follows:

Where the headers frame can be a single headers frame, or it can be a headers frame and a number of continuation frames immediately following it;
Similarly, the push_promise frame can be a single push_promise frame, or it can be a push_promise frame and a number of continuation frames immediately following it.

Note that only the state transitions of the stream and the frames and identities that affect the flow state transitions are shown in the figure. At this point, continuation frames do not affect the flow state transitions, they are only valid components of the front headers frame or push_promise frame.

To achieve the purpose of the state transition, the End_stream identity is treated as an independent event within the frame that contains it. In this way, a headers frame containing the End_stream identity can cause two state transitions. For example, a stream with a status of "reserved (remote)" is converted from a "reserved (remote)" state to a "semi-closed (local)" State after it receives a headers frame, and if the headers frame contains end_stream identity, the stream continues to transition from the "semi-closed (local)" State to " Off "status.

When a frame is in transit, each endpoint may have a subjective view of a different flow state. The creation of convection is not reconciled between endpoints, and each endpoint can create flows unilaterally. The negative consequences of a state mismatch are limited to the "off" state after the Rst_stream frame is sent, in which case the endpoint may still receive the frame for a period of time after the stream is closed.

The identifier of the stream

The stream is identified by an unsigned 31-bit integer. The client-initiated stream uses an odd ID, and the stream initialized by the server uses an even ID. A value of 0 (0x0) is used to identify the connection control message, and therefore cannot be used to establish a new connection.

An HTTP1.1 request that is upgraded to HTTP/2 receives a response that identifies a stream with a value of 0x1. When the upgrade is complete, the state of the stream 0x1 is "semi-closed (local)" for the client. Therefore, 0x1 cannot be selected as the identity of the new stream by the client that is upgraded from HTTP1.1. The identity of a newly established stream is required on a numeric value greater than the identity of any stream that has been opened or reserved on the creation side. This rule applies to streams that are opened with headers frames and those that are reserved with push_promise frames. Any endpoint that receives an expected stream identity will respond to a connection error of type Protocol_error.

A new stream identity is used for the first time and will implicitly close all streams that may have been initialized to the peer and that the stream identity value is less than the new identity in the "Idle" state. For example, if the client sends a headers frame on stream 7 and does not send any frames on stream 5 before, then stream 5 will be converted to the off state when the first frame of stream 7 is sent or received.

Stream identifiers cannot be reused. A long-lasting connection may cause the endpoint to run out of all possible identity values. Clients that cannot continue to establish a new stream identifier can create a new connection for subsequent new flows. The service side that cannot continue to establish a new stream identifier can send a goaway frame, forcing the client to use a new connection for the new stream.

Concurrency of a stream

Cond...

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

(iv) Flow of HTTP/2

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.