land_sdk/
http.rs

1//! `http` is a module for http request and response.
2
3use crate::body::Body as RawBody;
4
5/// `Body` is a wrapper around the wasi http_body API
6pub type Body = RawBody;
7/// `Request` is a wrapper around the wasi http_request API
8pub type Request = http::Request<Body>;
9/// `Response` is a wrapper around the wasi http_response API
10pub type Response = http::Response<Body>;
11
12// re-export http_outgoing into http crate
13pub use super::fetch::fetch;
14
15/// `RequestError` is error type when fetching request failed.
16pub type RequestError = super::http_service::land::http::http_outgoing::RequestError;
17/// `RequestOptions` is options for fetching request, including timeout and redirect policy.
18pub type RequestOptions = super::http_service::land::http::http_outgoing::RequestOptions;
19/// `RedirectPolicy` is redirect policy for fetching request.
20pub type RedirectPolicy = super::http_service::land::http::http_types::RedirectPolicy;
21
22/// `error_response` is a helper function to build a response with status code and message.
23pub fn error_response(status: http::StatusCode, message: String) -> Response {
24    let mut response = Response::new(message.into());
25    *response.status_mut() = status;
26    response
27}
28
29/// Error type for SDK, alias to `anyhow::Error`
30pub type Error = anyhow::Error;