← All compilation units

Flyology.HTTP.Client.Request_Bodies.Channels

Description

Adapts a bounded unique-buffer channel into a generated HTTP request body. Producers retain ordinary channel backpressure and close the channel to finish an unknown-length body. A channel source is deliberately one-shot and does not opt into Rewindable_Request_Body_Source retries.

Channel_Source

type Channel_Source
  (Pool  : not null access Flyology.Buffers.Pool;
   Input : not null access Flyology.Buffers.Channels.Channel)
is limited new Request_Body_Source with private;

Consume buffers from Input. Pool must be Input's owner. The source holds at most one received buffer between Read calls and releases each buffer after copying its payload into the HTTP transport's bounded staging array. Pool and Input must outlive the source and Execute.

Declared_Length

function Declared_Length
  (Item : Channel_Source) return Body_Length

@exclude

Parameters
Item

Channel source to inspect

Return value

Configured known or unknown length

Read

procedure Read
  (Item     : in out Channel_Source;
   Data     : out Ada.Streams.Stream_Element_Array;
   Last     : out Ada.Streams.Stream_Element_Offset;
   Finished : out Boolean;
   Timeout  : Duration;
   Token    : access Flyology.Cancellation.Token)

@exclude

Parameters
Item

Channel source to advance

Data

Client staging array

Last

Last produced byte

Finished

Whether the unknown channel is drained or the known byte count is complete

Timeout

Remaining exchange timeout

Token

Exchange cancellation token

Set_Declared_Length

procedure Set_Declared_Length
  (Item : in out Channel_Source; Length : Body_Length)

Set the framing length before Execute. Unknown_Length, the default, sends HTTP/1.1 chunked coding until Input closes and drains. A known length makes the client consume exactly that many bytes without waiting for Input to close. An early close or a received buffer that would cross the declared total raises Request_Body_Error. The length cannot change after reading starts.

Parameters
Item

Channel source to configure

Length

Known total byte count or Unknown_Length

Raised exceptions
Program_Error

Reading has already started