Skip to main content

HttpBodyStream

Struct HttpBodyStream 

Source
pub struct HttpBodyStream { /* private fields */ }
Expand description

An owned request body stream, confined to the ArkWeb I/O thread.

Reads consume the stream, so only one operation can use it at a time. Self::read returns ownership with the bytes; Self::read_to_end closes it on completion. Both initialize lazily, without rewinding subsequent reads. Callbacks may run inline and must own their captures ('static).

Once submitted, an operation owns the stream and buffer until its callback. If native code never completes it, those resources must remain allocated: ArkWeb provides no cancellation acknowledgement for outstanding writes.

Implementations§

Source§

impl HttpBodyStream

Source

pub unsafe fn new( raw: *mut ArkWeb_HttpBodyStream, ) -> Result<Self, HttpBodyStreamError>

Take exclusive ownership of a native body stream.

§Safety

raw must be null or a live stream returned by OH_ArkWebResourceRequest_GetHttpBodyStream, with no operations in flight. The caller must be on the ArkWeb I/O thread. No other owner may use, destroy, or change callbacks/userData on this stream after this call.

Source

pub fn initialize<F>(self, callback: F)
where F: FnOnce(Result<Self, HttpBodyStreamError>) + 'static,

Initialize without reading, returning the stream for metadata queries. Already initialized streams are returned without another native Init. All errors are delivered once through the callback, possibly inline.

Source

pub fn is_chunked(&self) -> Result<bool, HttpBodyStreamError>

Source

pub fn is_eof(&self) -> Result<bool, HttpBodyStreamError>

Source

pub fn is_in_memory(&self) -> Result<bool, HttpBodyStreamError>

Source

pub fn size(&self) -> Result<Option<u64>, HttpBodyStreamError>

Total body size after initialization: None for unknown-length chunked bodies, Some(0) for known empty bodies. Before initialization, errors.

Source

pub fn read<F>(self, size: usize, callback: F)
where F: FnOnce(Result<(Self, Vec<u8>), HttpBodyStreamError>) + 'static,

Read at most size bytes, returning the stream at its new position. A zero-sized read initializes but never calls native Read. On error the stream is closed. The callback is the sole result channel.

Ownership prevents overlapping reads at compile time:

ⓘ
fn overlap(stream: HttpBodyStream) {
    stream.read(1, |_| {});
    stream.read(1, |_| {}); // stream has moved into the first operation
}
Source

pub fn read_to_end<F>(self, callback: F)
where F: FnOnce(Result<Vec<u8>, HttpBodyStreamError>) + 'static,

Collect the remaining body through EOF and close the stream. Handles short reads and unknown lengths; errors also close the stream.

Trait Implementations§

Source§

impl Drop for HttpBodyStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.