Struct fastly::handle::BodyHandle
source · [−]#[repr(transparent)]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
An invalid body handle.
This is primarily useful to represent uninitialized values when using the interfaces in
fastly_sys
.
Returns true
if the body handle is invalid.
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.
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.
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.
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.
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()
.
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.
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.
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
.
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]);
Write a string slice to the end of this body, and return the number of bytes written.
Examples
body.write_str("woof woof");
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_str("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
Performs the conversion.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read
, except that it reads into a slice of buffers. Read more
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
Read all bytes until EOF in this source, placing them into buf
. Read more
Read all bytes until EOF in this source, appending them to buf
. Read more
Read the exact number of bytes required to fill buf
. Read more
read_buf
)Pull some bytes from this source into the specified buffer. Read more
read_buf
)Read the exact number of bytes required to fill buf
. Read more
Creates a “by reference” adaptor for this instance of Read
. Read more
Creates an adapter which will chain this stream with another. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more