Struct fastly::handle::BodyHandle

source ·
pub struct BodyHandle { /* private fields */ }
Expand description

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.

Implementations§

source§

impl BodyHandle

source

pub const INVALID: Self = _

An invalid body handle.

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

source

pub const fn is_valid(&self) -> bool

Returns true if the body handle is valid.

source

pub const fn is_invalid(&self) -> bool

Returns true if the body handle is invalid.

source

pub unsafe fn from_u32(handle: u32) -> Self

Make a handle from its underlying representation.

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

source

pub unsafe fn as_u32(&self) -> u32

Get the underlying representation of the handle.

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

source

pub unsafe fn as_u32_mut(&mut self) -> &mut u32

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

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

source

pub fn into_u32(self) -> u32

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

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

source

pub 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().

source

pub fn new() -> Self

Acquire a new, empty body handle.

source

pub 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.

source

pub 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.

source

pub 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.

source

pub 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()?;

Trait Implementations§

source§

impl BodyHandleExt for BodyHandle

source§

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

Get the names of the trailers associated with this body. Read more
source§

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

Get the value for the trailer with the given name. Read more
source§

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

Get all the values associated with the trailer with the given name. Read more
source§

impl Debug for BodyHandle

source§

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

Formats the value using the given formatter. Read more
source§

impl Drop for BodyHandle

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<&[u8]> for BodyHandle

source§

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

Converts to this type from the input type.
source§

impl From<&str> for BodyHandle

source§

fn from(s: &str) -> Self

Converts to this type from the input type.
source§

impl From<BodyHandle> for Body

source§

fn from(handle: BodyHandle) -> Self

Converts to this type from the input type.
source§

impl From<String> for BodyHandle

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl From<Vec<u8>> for BodyHandle

source§

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

Converts to this type from the input type.
source§

impl Hash for BodyHandle

source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for BodyHandle

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Read for BodyHandle

source§

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

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

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

Read the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

impl Write for BodyHandle

source§

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

Write a buffer into this writer, returning how many bytes were written. Read more
source§

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

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · source§

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

Attempts to write an entire buffer into this writer. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
source§

impl Eq for BodyHandle

source§

impl StructuralPartialEq for BodyHandle

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.