BodyHandle

Structin handlefastly 0.13.1View source
pub struct BodyHandle { /* private fields */ }

A low-level interface to HTTP bodies.

For most applications, you should use Body instead of this interface. See the top-level handle documentation for more details.

This type implements Read to read bytes from the beginning of a body, and Write to write to the end of a body. Note that these operations are unbuffered, unlike the same operations on the higher-level Body type.

Constants

INVALID

Selfread-onlyView source

An invalid body handle.

This is primarily useful to represent uninitialized values when using the interfaces in fastly_sys.

Methods

fn append(&mut self, other: BodyHandle)

Append another body onto the end of this body.

This operation is performed in amortized constant time, and so should always be preferred to reading an entire body and then writing the same contents to another body.

The other body will no longer be valid after this call.

Parameters

self: &mut Self
other: BodyHandle
unsafe fn as_u32(&self) -> u32

Get the underlying representation of the handle.

Safety

This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.

Parameters

self: &Self

Returns

u32

as_u32_mut

View source
unsafe fn as_u32_mut(&mut self) -> &mut u32

Get a mutable reference to the underlying u32 representation of the handle.

Safety

This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.

Parameters

self: &mut Self

Returns

&mut u32
fn close(self) -> Result<(), HandleError>

Close the BodyHandle by removing it from the host Session. This will close out streaming and non streaming bodies. Care must be taken to only close out the handle if the body is not being written to or read from anymore. If the handle has already been closed an error will be returned.

Examples

let mut body = BodyHandle::new();
body.write_all(b"You're already closed.")?;
// The handle is not being used in a request and doesn't refer to any
// response body so we can close this out
body.close()?;

Parameters

self: Self

Returns

from_client

View source
fn from_client() -> Self

Get a handle to the client request body.

This handle may only be retrieved once per execution, either through this function or through client_request_and_body().

Returns

Self

from_u32

View source
unsafe fn from_u32(handle: u32) -> Self

Make a handle from its underlying representation.

Safety

This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.

Parameters

handle: u32

Returns

Self

into_bytes

View source
fn into_bytes(self) -> Vec<u8>

Read the entirety of the body into a byte vector.

Memory usage

This method will cause the entire body to be buffered in WebAssembly memory. You should take care not to exceed the WebAssembly memory limits, and consider using Read methods to control how much of the body you process at once.

Parameters

self: Self

Returns

Vec<u8>

into_string

View source
fn into_string(self) -> String

Read the entirety of the body into a String, interpreting the bytes as UTF-8.

Memory usage

This method will cause the entire body to be buffered in WebAssembly memory. You should take care not to exceed the WebAssembly memory limits, and consider using Read methods to control how much of the body you process at once.

Panics

If the body does not contain a valid UTF-8 string, this function will panic. To explicitly handle the possibility of invalid UTF-8 data, use into_bytes() and then convert the bytes explicitly with a function like String::from_utf8.

Parameters

self: Self

Returns

String

into_u32

View source
fn into_u32(self) -> u32

Turn a handle into its representation without closing the underlying resource.

Safety

This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.

Parameters

self: Self

Returns

u32

is_invalid

View source
const fn is_invalid(&self) -> bool

Returns true if the body handle is invalid.

Parameters

self: &Self

Returns

bool

is_valid

View source
const fn is_valid(&self) -> bool

Returns true if the body handle is valid.

Parameters

self: &Self

Returns

bool
fn new() -> Self

Acquire a new, empty body handle.

Returns

Self

Trait implementations

impl BodyHandleExt for BodyHandle

get_trailer_names

View source
fn get_trailer_names<'a>(&'a self, buf_size: usize) -> Result<Box<(dyn Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a)>, BodyHandleError>

Parameters

self: &Self
buf_size: usize

Returns

Result<Box<(dyn Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a)>, BodyHandleError>

get_trailer_value

View source
fn get_trailer_value(&self, name: &HeaderName, max_len: usize) -> Result<Result<Option<HeaderValue>, BufferSizeError>, BodyHandleError>

Parameters

self: &Self
name: &HeaderName
max_len: usize

Returns

get_trailer_values

View source
fn get_trailer_values<'a>(&'a self, name: &'a HeaderName, max_len: usize) -> Result<Box<(dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a)>, BodyHandleError>

Parameters

self: &Self
name: &HeaderName
max_len: usize

Returns

Result<Box<(dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a)>, BodyHandleError>

impl Debug for BodyHandle

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Parameters

self: &Self
f: &mut $crate::fmt::Formatter

Returns

$crate::fmt::Result

impl Drop for BodyHandle

fn drop(&mut self)

Parameters

self: &mut Self

impl From<&[u8]> for BodyHandle

fn from(s: &[u8]) -> Self

Parameters

s: &[u8]

Returns

Self

impl From<&str> for BodyHandle

fn from(s: &str) -> Self

Parameters

s: &str

Returns

Self

impl From<String> for BodyHandle

fn from(s: String) -> Self

Parameters

s: String

Returns

Self

impl From<Vec<u8>> for BodyHandle

fn from(s: Vec<u8>) -> Self

Parameters

s: Vec<u8>

Returns

Self

impl Hash for BodyHandle

fn hash<__H: Hasher>(&self, state: &mut __H)

Parameters

self: &Self
state: &mut __H

impl PartialEq for BodyHandle

fn eq(&self, other: &Self) -> bool

Parameters

self: &Self
other: &Self

Returns

bool

impl Read for BodyHandle

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Parameters

self: &mut Self
buf: &mut [u8]

Returns

std::io::Result<usize>

impl Write for BodyHandle

fn flush(&mut self) -> Result<()>

Parameters

self: &mut Self

Returns

std::io::Result<()>
fn write(&mut self, buf: &[u8]) -> Result<usize>

Parameters

self: &mut Self
buf: &[u8]

Returns

std::io::Result<usize>

Auto trait implementations

Blanket implementations