Skip to content

Commit 2052a1a

Browse files
committed
Document how libnghttp2 schedules HTTP/2 frames internally
1 parent 183be9c commit 2052a1a

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

doc/programmers-guide.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,51 @@ Any deviation results in stream error of type PROTOCOL_ERROR. If
177177
error is found in PUSH_PROMISE frame, stream error is raised against
178178
promised stream.
179179

180+
The order of transmission of the HTTP/2 frames
181+
----------------------------------------------
182+
183+
This section describes the internals of libnghttp2 about the
184+
scheduling of transmission of HTTP/2 frames. This is pretty much
185+
internal stuff, so the details could change in the future versions of
186+
the library.
187+
188+
libnghttp2 categorizes HTTP/2 frames into 4 categories: urgent,
189+
regular, syn_stream, and data in the order of higher priority.
190+
191+
The urgent category includes PING and SETTINGS. They are sent with
192+
highest priority. The order inside the category is FIFO.
193+
194+
The regular category includes frames other than PING, SETTINGS, DATA,
195+
and HEADERS which does not create stream (which counts toward
196+
concurrent stream limit). The order inside the category is FIFO.
197+
198+
The syn_stream category includes HEADERS frame which creates stream,
199+
that counts toward the concurrent stream limit.
200+
201+
The data category includes DATA frame, and the scheduling among DATA
202+
frames are determined by HTTP/2 dependency tree.
203+
204+
If the application wants to send frames in the specific order, and the
205+
default transmission order does not fit, it has to schedule frames by
206+
itself using the callbacks (e.g.,
207+
:type:`nghttp2_on_frame_send_callback`).
208+
209+
For example, suppose that application wants to send RST_STREAM after
210+
sending response HEADERS and DATA. Because of the reason we mentioned
211+
above, the following code does not work:
212+
213+
.. code-block:: c
214+
215+
nghttp2_submit_response(...)
216+
nghttp2_submit_rst_stream(...)
217+
218+
This is because HEADERS submitted by `nghttp2_submit_response()` is
219+
scheduled after RST_STREAM submitted by `nghttp2_submit_rst_stream()`.
220+
221+
The correct way is use :type:`nghttp2_on_frame_send_callback`, and
222+
after HEADERS and DATA frames are sent, issue
223+
`nghttp2_submit_rst_stream()`.
224+
180225
Implement user defined HTTP/2 non-critical extensions
181226
-----------------------------------------------------
182227

0 commit comments

Comments
 (0)