pub struct WriteContext<'a>(/* private fields */);Expand description
Request, response and read-write KV access for one call of a
Registry::read_write handler.
Borrowed request data must be copied before calling a &mut self method,
and cannot outlive the context:
use ccf_app::{EndpointResult, WriteContext};
fn echo(context: &mut WriteContext<'_>) -> EndpointResult {
let body = context.body()?;
context.set_body(body)?;
Ok(())
}use ccf_app::WriteContext;
fn retain_body(context: &WriteContext<'_>) -> &'static [u8] {
context.body().unwrap()
}Implementations§
Source§impl<'ctx> WriteContext<'ctx>
impl<'ctx> WriteContext<'ctx>
Sourcepub fn body(&self) -> BridgeResult<&[u8]>
pub fn body(&self) -> BridgeResult<&[u8]>
Borrow the raw request body. Copy it before calling a &mut self method
if it is still needed.
Sourcepub fn query(&self) -> BridgeResult<&str>
pub fn query(&self) -> BridgeResult<&str>
Borrow the raw query string, without the leading ? and not
percent-decoded.
Sourcepub fn path_param(&mut self, name: &str) -> BridgeResult<Option<String>>
pub fn path_param(&mut self, name: &str) -> BridgeResult<Option<String>>
Copy the decoded path parameter name, such as "key" for
/records/{key}, or None if it is absent.
Sourcepub fn header(&mut self, name: &str) -> BridgeResult<Option<Vec<u8>>>
pub fn header(&mut self, name: &str) -> BridgeResult<Option<Vec<u8>>>
Copy the raw value of the request header name, which must be
lowercase, or None if it is absent.
Sourcepub fn set_status(&mut self, status: u16) -> BridgeResult<()>
pub fn set_status(&mut self, status: u16) -> BridgeResult<()>
Set the response status. Unknown statuses are rejected with
BridgeError::InvalidArgument.
Sourcepub fn set_header(&mut self, name: &str, value: &str) -> BridgeResult<()>
pub fn set_header(&mut self, name: &str, value: &str) -> BridgeResult<()>
Set a response header. Invalid names and values, including any
containing CR or LF, are rejected with BridgeError::InvalidArgument.
Sourcepub fn set_body(&mut self, body: &[u8]) -> BridgeResult<()>
pub fn set_body(&mut self, body: &[u8]) -> BridgeResult<()>
Set the raw response body.