Flow control

HTTP/2 defines two levels of flow control (RFC 9113 §5.2): the connection-level window and a per-stream window. PureHTTP2.jl models both as FlowControlWindow instances. The FlowController ties them together — it owns one connection window and a dictionary of stream windows keyed by stream ID, and its operations correctly decrement both windows when a stream sends or receives DATA.

Above that, DataSender and DataReceiver layer frame-size limits on top of the flow controller, splitting outgoing DATA into frames no larger than the peer's MAX_FRAME_SIZE.

Role signalling

Flow control is role-neutral. A FlowControlWindow is a sliding window regardless of who created it, and the FlowController distinguishes only connection-level from stream-level — never server from client. The apply_settings_initial_window_size! function responds to a peer's SETTINGS frame the same way whether that frame came from a server or a client.

Client-role code that sends DATA constructs the same DataSender shape as server-role code; the roles diverge only in which side originally advertises the initial window.

Window

PureHTTP2.FlowControlWindowType
FlowControlWindow(initial_size::Int = DEFAULT_INITIAL_WINDOW_SIZE)

A single HTTP/2 flow-control window (RFC 9113 §5.2). Can represent either a connection-level window or a stream-level window. Thread- safe via an internal ReentrantLock.

Fields

  • available::Int: Available window size
  • initial_size::Int: Initial window size
  • pending_updates::Int: Pending WINDOW_UPDATE bytes to send
  • lock::ReentrantLock: Thread-safe access

Example

julia> using PureHTTP2

julia> window = FlowControlWindow(65535);

julia> consume!(window, 1000)
true

julia> available(window)
64535

julia> release!(window, 1000);

julia> available(window)
65535
source

Window operations

PureHTTP2.consume!Function
consume!(window::FlowControlWindow, size::Int) -> Bool

Consume bytes from the flow control window. Returns true if consumption was successful, false if insufficient window.

source
PureHTTP2.try_consume!Function
try_consume!(window::FlowControlWindow, size::Int) -> Int

Try to consume up to size bytes from the window. Returns the actual number of bytes consumed.

source
PureHTTP2.release!Function
release!(window::FlowControlWindow, size::Int)

Release bytes back to the flow control window (for WINDOW_UPDATE).

source
PureHTTP2.should_send_updateFunction
should_send_update(window::FlowControlWindow; threshold_ratio::Float64=0.5) -> Bool

Check if a WINDOW_UPDATE should be sent based on pending updates.

source
PureHTTP2.update_initial_size!Function
update_initial_size!(window::FlowControlWindow, new_initial_size::Int)

Update the initial window size (from SETTINGS frame). Adjusts the current available window proportionally.

source

Multi-stream controller

PureHTTP2.FlowControllerType
FlowController

Manages flow control for an HTTP/2 connection.

Fields

  • connection_window::FlowControlWindow: Connection-level window
  • stream_windows::Dict{UInt32, FlowControlWindow}: Per-stream windows
  • initial_stream_window::Int: Initial window size for new streams
  • lock::ReentrantLock: Thread-safe access to stream windows dict
source

Controller operations

PureHTTP2.create_stream_window!Function
create_stream_window!(controller::FlowController, stream_id::UInt32) -> FlowControlWindow

Create a flow control window for a new stream.

source
PureHTTP2.get_stream_windowFunction
get_stream_window(controller::FlowController, stream_id::UInt32) -> Union{FlowControlWindow, Nothing}

Get the flow control window for a stream.

source
PureHTTP2.consume_send!Function
consume_send!(controller::FlowController, stream_id::UInt32, size::Int) -> Bool

Consume bytes from both connection and stream windows for sending.

source
PureHTTP2.max_sendableFunction
max_sendable(controller::FlowController, stream_id::UInt32) -> Int

Get the maximum sendable bytes considering both connection and stream windows.

source
PureHTTP2.apply_window_update!Function
apply_window_update!(controller::FlowController, stream_id::UInt32, increment::Int)

Apply a received WINDOW_UPDATE to the appropriate window. Stream ID 0 updates the connection window.

source
PureHTTP2.generate_window_updatesFunction
generate_window_updates(controller::FlowController;
                        threshold_ratio::Float64=0.5) -> Vector{Frame}

Generate WINDOW_UPDATE frames for windows that need updating.

source

High-level senders and receivers

PureHTTP2.DataSenderType
DataSender

Manages sending data with flow control and frame size limits.

Fields

  • controller::FlowController: Flow controller
  • max_frame_size::Int: Maximum frame payload size
source
PureHTTP2.send_data_framesFunction
send_data_frames(sender::DataSender, stream_id::UInt32, data::Vector{UInt8};
                 end_stream::Bool=false) -> Vector{Frame}

Split data into frames respecting flow control and frame size limits. Returns empty vector if no data can be sent due to flow control.

source
PureHTTP2.DataReceiverType
DataReceiver

Manages receiving data with flow control.

Fields

  • controller::FlowController: Flow controller
  • max_frame_size::Int: Maximum allowed frame payload size
source