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
impl BodyHandle
sourcepub const INVALID: Self = _
pub const INVALID: Self = _
An invalid body handle.
This is primarily useful to represent uninitialized values when using the interfaces in
fastly_sys
.
sourcepub const fn is_invalid(&self) -> bool
pub const fn is_invalid(&self) -> bool
Returns true
if the body handle is invalid.
sourcepub unsafe fn from_u32(handle: u32) -> Self
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.
sourcepub unsafe fn as_u32(&self) -> u32
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.
sourcepub unsafe fn as_u32_mut(&mut self) -> &mut u32
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.
sourcepub fn into_u32(self) -> u32
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.
sourcepub fn from_client() -> Self
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()
.
sourcepub fn append(&mut self, other: BodyHandle)
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.
sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
sourcepub fn into_string(self) -> String
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
.
sourcepub fn write_bytes(&mut self, bytes: &[u8]) -> usize
👎Deprecated since 0.9.3: use std::io::Write::write() instead
pub fn write_bytes(&mut self, bytes: &[u8]) -> usize
Write a slice of bytes to the end of this body, and return the number of bytes written.
§Examples
body.write_bytes(&[0, 1, 2, 3]);
sourcepub fn write_str(&mut self, string: &str) -> usize
👎Deprecated since 0.9.3: use std::io::Write::write() instead
pub fn write_str(&mut self, string: &str) -> usize
Write a string slice to the end of this body, and return the number of bytes written.
§Examples
body.write_str("woof woof");
sourcepub fn close(self) -> Result<(), HandleError>
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
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>
fn get_trailer_names<'a>( &'a self, buf_size: usize ) -> Result<Box<dyn Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a>, BodyHandleError>
source§fn get_trailer_value(
&self,
name: &HeaderName,
max_len: usize
) -> Result<Result<Option<HeaderValue>, BufferSizeError>, BodyHandleError>
fn get_trailer_value( &self, name: &HeaderName, max_len: usize ) -> Result<Result<Option<HeaderValue>, BufferSizeError>, BodyHandleError>
source§fn get_trailer_values<'a>(
&'a self,
name: &'a HeaderName,
max_len: usize
) -> Result<Box<dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a>, BodyHandleError>
fn get_trailer_values<'a>( &'a self, name: &'a HeaderName, max_len: usize ) -> Result<Box<dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a>, BodyHandleError>
source§impl Debug for BodyHandle
impl Debug for BodyHandle
source§impl Drop for BodyHandle
impl Drop for BodyHandle
source§impl From<&[u8]> for BodyHandle
impl From<&[u8]> for BodyHandle
source§impl From<&str> for BodyHandle
impl From<&str> for BodyHandle
source§impl From<BodyHandle> for Body
impl From<BodyHandle> for Body
source§fn from(handle: BodyHandle) -> Self
fn from(handle: BodyHandle) -> Self
source§impl From<String> for BodyHandle
impl From<String> for BodyHandle
source§impl Hash for BodyHandle
impl Hash for BodyHandle
source§impl PartialEq for BodyHandle
impl PartialEq for BodyHandle
source§fn eq(&self, other: &BodyHandle) -> bool
fn eq(&self, other: &BodyHandle) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Read for BodyHandle
impl Read for BodyHandle
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl Write for BodyHandle
impl Write for BodyHandle
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)