Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c3af8fd
feat: add wasi http experimental
eduardomourar Feb 9, 2023
e707e13
feat: add bindings crate
eduardomourar Feb 10, 2023
c5da583
feat: return monadic type for http request
eduardomourar Feb 12, 2023
6b7faa4
chore: rename main http function to send
eduardomourar Feb 12, 2023
8c6043e
chore: update wit-bindgen in bindings crate
eduardomourar Feb 13, 2023
9dc2233
chore: change http method to enum
eduardomourar Feb 14, 2023
72116e3
chore: remove http status error
eduardomourar Feb 14, 2023
b2382e6
Merge branch 'main' into feat/wasi-http-experimental
eduardomourar Feb 19, 2023
bae5545
feat: use new wasi-http wit definition
eduardomourar Feb 23, 2023
922f4a7
Merge remote-tracking branch 'origin/main' into feat/wasi-http-experi…
eduardomourar Feb 23, 2023
dd74ffc
Merge remote-tracking branch 'origin/main' into feat/wasi-http-experi…
eduardomourar Mar 13, 2023
1e38e23
chore: add basic scaffolding for wasi http
eduardomourar Mar 14, 2023
e8cbfcd
Merge remote-tracking branch 'origin/main' into feat/wasi-http-experi…
eduardomourar Mar 14, 2023
0bb1f0e
chore: revert rename for http types
eduardomourar Mar 17, 2023
533894a
chore: changes based on review feedback
eduardomourar Mar 17, 2023
0933bc4
chore: add modules to verify
eduardomourar Mar 17, 2023
09b0c8d
chore: include features wasi bindings
eduardomourar Mar 17, 2023
7f41229
chore: update lock file
eduardomourar Mar 17, 2023
bce17d1
chore: fix formatting
eduardomourar Mar 17, 2023
cdac89d
chore: fix casing for http imported names
eduardomourar Mar 17, 2023
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
Prev Previous commit
Next Next commit
feat: return monadic type for http request
  • Loading branch information
eduardomourar committed Feb 13, 2023
commit c5da58378d1a689c6be3773827ad63690c0e3f36
16 changes: 11 additions & 5 deletions host/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{
wasi_http::{Request, Response, WasiHttp},
WasiCtx
wasi_http::{HttpError, Request, Response, WasiHttp},
HostResult, WasiCtx
};
use reqwest::{Client, Method};

#[async_trait::async_trait]
impl WasiHttp for WasiCtx {
async fn make_request(&mut self, req: Request) -> anyhow::Result<Response> {
async fn make_request(&mut self, req: Request) -> HostResult<Response, HttpError> {
let client = Client::default();
let mut builder = client.request(
Method::from_bytes(req.method.as_bytes())?,
Expand All @@ -25,10 +25,16 @@ impl WasiHttp for WasiCtx {
));
}
let body = Some(res.bytes().await?.to_vec());
Ok(Response {
Ok(Ok(Response {
status,
headers: Some(headers),
body,
})
}))
}
}

impl From<reqwest::Error> for HttpError {
fn from(e: reqwest::Error) -> Self {
Self::UnexpectedError(e.to_string())
}
}
11 changes: 10 additions & 1 deletion wit/wasi-http.wit
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,14 @@ default interface wasi-http {
body: option<body>,
}

make-request: func(req: request) -> response
/// HTTP errors returned by the runtime.
variant http-error {
invalid-url(string),
timeout-error(string),
protocol-error(string),
status-error(u16),
unexpected-error(string)
}

make-request: func(req: request) -> result<response, http-error>
}