Struct wasi::http::types::ResponseOutparam
source · pub struct ResponseOutparam { /* private fields */ }
Expand description
Represents the ability to send an HTTP Response.
This resource is used by the wasi:http/incoming-handler
interface to
allow a Response to be sent corresponding to the Request provided as the
other argument to incoming-handler.handle
.
Implementations§
source§impl ResponseOutparam
impl ResponseOutparam
sourcepub fn set(
param: ResponseOutparam,
response: Result<OutgoingResponse, ErrorCode>
)
pub fn set( param: ResponseOutparam, response: Result<OutgoingResponse, ErrorCode> )
Set the value of the response-outparam
to either send a response,
or indicate an error.
This method consumes the response-outparam
to ensure that it is
called at most once. If it is never called, the implementation
will respond with an error.
The user may provide an error
to response
to allow the
implementation determine how to respond with an HTTP error response.
Examples found in repository?
examples/http-proxy-no_std.rs (line 14)
10 11 12 13 14 15 16 17 18 19 20 21
fn handle(_request: IncomingRequest, response_out: ResponseOutparam) {
let resp = OutgoingResponse::new(Fields::new());
let body = resp.body().unwrap();
ResponseOutparam::set(response_out, Ok(resp));
let out = body.write().unwrap();
out.blocking_write_and_flush(b"Hello, WASI!").unwrap();
drop(out);
OutgoingBody::finish(body, None).unwrap();
}
More examples
examples/http-proxy.rs (line 16)
12 13 14 15 16 17 18 19 20 21 22 23 24
fn handle(_request: IncomingRequest, response_out: ResponseOutparam) {
let resp = OutgoingResponse::new(Fields::new());
let body = resp.body().unwrap();
ResponseOutparam::set(response_out, Ok(resp));
let mut out = body.write().unwrap();
out.write_all(b"Hello, WASI!").unwrap();
out.flush().unwrap();
drop(out);
OutgoingBody::finish(body, None).unwrap();
}
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ResponseOutparam
impl RefUnwindSafe for ResponseOutparam
impl Send for ResponseOutparam
impl Sync for ResponseOutparam
impl Unpin for ResponseOutparam
impl UnwindSafe for ResponseOutparam
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more