BodyHandle
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
An invalid body handle.
This is primarily useful to represent uninitialized values when using the interfaces in
fastly_sys.
Methods
append
View sourcefn 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
as_u32
View sourceunsafe fn as_u32(&self) -> u32Get 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
as_u32_mut
View sourceunsafe fn as_u32_mut(&mut self) -> &mut u32Get 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
close
View sourceClose 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 outbody.close()?;Parameters
- self: Self
Returns
from_client
View sourcefn from_client() -> SelfGet 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
from_u32
View sourceunsafe fn from_u32(handle: u32) -> SelfMake 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
into_bytes
View sourceRead 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
into_string
View sourcefn into_string(self) -> StringRead 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
into_u32
View sourcefn into_u32(self) -> u32Turn 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
is_invalid
View sourceconst fn is_invalid(&self) -> boolReturns true if the body handle is invalid.
Parameters
- self: &Self
Returns
is_valid
View sourceconst fn is_valid(&self) -> boolReturns true if the body handle is valid.
Parameters
- self: &Self
Returns
Trait implementations
impl BodyHandleExt for BodyHandle
get_trailer_names
View sourcefn 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
get_trailer_value
View sourcefn 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 sourcefn 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