Struct wasi::http::types::OutgoingResponse
source · pub struct OutgoingResponse { /* private fields */ }
Expand description
Represents an outgoing HTTP Response.
Implementations§
source§impl OutgoingResponse
impl OutgoingResponse
sourcepub fn new(headers: Headers) -> Self
pub fn new(headers: Headers) -> Self
Construct an outgoing-response
, with a default status-code
of 200
.
If a different status-code
is needed, it must be set via the
set-status-code
method.
headers
is the HTTP Headers for the Response.
Examples found in repository?
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
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();
}
source§impl OutgoingResponse
impl OutgoingResponse
sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Get the HTTP Status Code for the Response.
source§impl OutgoingResponse
impl OutgoingResponse
sourcepub fn set_status_code(&self, status_code: StatusCode) -> Result<(), ()>
pub fn set_status_code(&self, status_code: StatusCode) -> Result<(), ()>
Set the HTTP Status Code for the Response. Fails if the status-code given is not a valid http status code.
source§impl OutgoingResponse
impl OutgoingResponse
sourcepub fn headers(&self) -> Headers
pub fn headers(&self) -> Headers
Get the headers associated with the Request.
The returned headers
resource is immutable: set
, append
, and
delete
operations will fail with header-error.immutable
.
This headers resource is a child: it must be dropped before the parent
outgoing-request
is dropped, or its ownership is transfered to
another component by e.g. outgoing-handler.handle
.
source§impl OutgoingResponse
impl OutgoingResponse
sourcepub fn body(&self) -> Result<OutgoingBody, ()>
pub fn body(&self) -> Result<OutgoingBody, ()>
Returns the resource corresponding to the outgoing Body for this Response.
Returns success on the first call: the outgoing-body
resource for
this outgoing-response
can be retrieved at most once. Subsequent
calls will return error.
Examples found in repository?
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
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();
}