Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-sdk: Make OutboundHttpError public #1518

Merged
merged 1 commit into from
May 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions sdk/rust/src/outbound_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ use http_types::{header::HeaderName, HeaderValue};

use super::http::{Request, Response};

wit_bindgen_rust::import!("../../wit/ephemeral/wasi-outbound-http.wit");
#[allow(missing_docs)]
pub(crate) mod wit {
wit_bindgen_rust::import!("../../wit/ephemeral/wasi-outbound-http.wit");
pub use wasi_outbound_http::*;
}

use wit::{Request as OutboundRequest, Response as OutboundResponse};

use wasi_outbound_http::{
HttpError as OutboundHttpError, Request as OutboundRequest, Response as OutboundResponse,
};
/// Error type returned by [`send_request`]
pub use wit::HttpError as OutboundHttpError;

type Result<T> = std::result::Result<T, OutboundHttpError>;

Expand Down Expand Up @@ -40,7 +45,7 @@ pub fn send_request(req: Request) -> Result<Response> {
status,
headers,
body,
} = wasi_outbound_http::request(out_req)?;
} = wit::request(out_req)?;

let resp_builder = http_types::response::Builder::new().status(status);
let resp_builder = headers
Expand All @@ -64,12 +69,12 @@ fn try_header_to_strs<'k, 'v>(
))
}

impl TryFrom<http_types::Method> for wasi_outbound_http::Method {
impl TryFrom<http_types::Method> for wit::Method {
type Error = OutboundHttpError;

fn try_from(method: http_types::Method) -> Result<Self> {
use http_types::Method;
use wasi_outbound_http::Method::*;
use wit::Method::*;
Ok(match method {
Method::GET => Get,
Method::POST => Post,
Expand All @@ -78,7 +83,7 @@ impl TryFrom<http_types::Method> for wasi_outbound_http::Method {
Method::PATCH => Patch,
Method::HEAD => Head,
Method::OPTIONS => Options,
_ => return Err(wasi_outbound_http::HttpError::RequestError),
_ => return Err(wit::HttpError::RequestError),
})
}
}
Expand Down