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 all commits
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
16 changes: 16 additions & 0 deletions host/src/default_outgoing_http.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::{
wasi,
wasi::types::{FutureIncomingResponse as Response, OutgoingRequest as Request, RequestOptions},
WasiCtx,
};

#[async_trait::async_trait]
impl wasi::default_outgoing_http::Host for WasiCtx {
async fn handle(
&mut self,
_req: Request,
_options: Option<RequestOptions>,
) -> wasmtime::Result<Response> {
anyhow::bail!("not implemented")
}
}
12 changes: 12 additions & 0 deletions host/src/http.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{
wasi,
wasi::types::{IncomingRequest as Request, ResponseOutparam as Response},
WasiCtx,
};

#[async_trait::async_trait]
impl wasi::http::Host for WasiCtx {
async fn handle(&mut self, _req: Request, _resp: Response) -> anyhow::Result<()> {
anyhow::bail!("not implemented")
}
}
203 changes: 203 additions & 0 deletions host/src/http_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
use crate::{
wasi,
wasi::poll::Pollable,
wasi::types::{
Error, Fields, FutureIncomingResponse, Headers, IncomingRequest, IncomingResponse,
IncomingStream, Method, OutgoingRequest, OutgoingResponse, OutgoingStream,
ResponseOutparam, Scheme, StatusCode, Trailers,
},
WasiCtx,
};

#[async_trait::async_trait]
impl wasi::types::Host for WasiCtx {
async fn drop_fields(&mut self, _fields: Fields) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn new_fields(&mut self, _entries: Vec<(String, String)>) -> wasmtime::Result<Fields> {
anyhow::bail!("not implemented")
}
async fn fields_get(
&mut self,
_fields: Fields,
_name: String,
) -> wasmtime::Result<Vec<String>> {
anyhow::bail!("not implemented")
}
async fn fields_set(
&mut self,
_fields: Fields,
_name: String,
_value: Vec<String>,
) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn fields_delete(&mut self, _fields: Fields, _name: String) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn fields_append(
&mut self,
_fields: Fields,
_name: String,
_value: String,
) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn fields_entries(&mut self, _fields: Fields) -> wasmtime::Result<Vec<(String, String)>> {
anyhow::bail!("not implemented")
}
async fn fields_clone(&mut self, _fields: Fields) -> wasmtime::Result<Fields> {
anyhow::bail!("not implemented")
}
async fn finish_incoming_stream(
&mut self,
_s: IncomingStream,
) -> wasmtime::Result<Option<Trailers>> {
anyhow::bail!("not implemented")
}
async fn finish_outgoing_stream(
&mut self,
_s: OutgoingStream,
_trailers: Option<Trailers>,
) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn drop_incoming_request(&mut self, _request: IncomingRequest) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn drop_outgoing_request(&mut self, _request: OutgoingRequest) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn incoming_request_method(
&mut self,
_request: IncomingRequest,
) -> wasmtime::Result<Method> {
anyhow::bail!("not implemented")
}
async fn incoming_request_path(
&mut self,
_request: IncomingRequest,
) -> wasmtime::Result<String> {
anyhow::bail!("not implemented")
}
async fn incoming_request_scheme(
&mut self,
_request: IncomingRequest,
) -> wasmtime::Result<Option<Scheme>> {
anyhow::bail!("not implemented")
}
async fn incoming_request_authority(
&mut self,
_request: IncomingRequest,
) -> wasmtime::Result<String> {
anyhow::bail!("not implemented")
}
async fn incoming_request_headers(
&mut self,
_request: IncomingRequest,
) -> wasmtime::Result<Headers> {
anyhow::bail!("not implemented")
}
async fn incoming_request_consume(
&mut self,
_request: IncomingRequest,
) -> wasmtime::Result<Result<IncomingStream, ()>> {
anyhow::bail!("not implemented")
}
async fn incoming_request_query(
&mut self,
_request: IncomingRequest,
) -> wasmtime::Result<String> {
anyhow::bail!("not implemented")
}
async fn new_outgoing_request(
&mut self,
_method: Method,
_path: String,
_query: String,
_scheme: Option<Scheme>,
_authority: String,
_headers: Headers,
) -> wasmtime::Result<OutgoingRequest> {
anyhow::bail!("not implemented")
}
async fn outgoing_request_write(
&mut self,
_request: OutgoingRequest,
) -> wasmtime::Result<Result<OutgoingStream, ()>> {
anyhow::bail!("not implemented")
}
async fn drop_response_outparam(
&mut self,
_response: ResponseOutparam,
) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn set_response_outparam(
&mut self,
_response: Result<OutgoingResponse, Error>,
) -> wasmtime::Result<Result<(), ()>> {
anyhow::bail!("not implemented")
}
async fn drop_incoming_response(
&mut self,
_response: IncomingResponse,
) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn drop_outgoing_response(
&mut self,
_response: OutgoingResponse,
) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn incoming_response_status(
&mut self,
_response: IncomingResponse,
) -> wasmtime::Result<StatusCode> {
anyhow::bail!("not implemented")
}
async fn incoming_response_headers(
&mut self,
_response: IncomingResponse,
) -> wasmtime::Result<Headers> {
anyhow::bail!("not implemented")
}
async fn incoming_response_consume(
&mut self,
_response: IncomingResponse,
) -> wasmtime::Result<Result<IncomingStream, ()>> {
anyhow::bail!("not implemented")
}
async fn new_outgoing_response(
&mut self,
_status_code: StatusCode,
_headers: Headers,
) -> wasmtime::Result<OutgoingResponse> {
anyhow::bail!("not implemented")
}
async fn outgoing_response_write(
&mut self,
_response: OutgoingResponse,
) -> wasmtime::Result<Result<OutgoingStream, ()>> {
anyhow::bail!("not implemented")
}
async fn drop_future_incoming_response(
&mut self,
_f: FutureIncomingResponse,
) -> wasmtime::Result<()> {
anyhow::bail!("not implemented")
}
async fn future_incoming_response_get(
&mut self,
_f: FutureIncomingResponse,
) -> wasmtime::Result<Option<Result<IncomingResponse, Error>>> {
anyhow::bail!("not implemented")
}
async fn listen_to_future_incoming_response(
&mut self,
_f: FutureIncomingResponse,
) -> wasmtime::Result<Pollable> {
anyhow::bail!("not implemented")
}
}
6 changes: 6 additions & 0 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
mod clocks;
mod default_outgoing_http;
mod env;
mod exit;
mod filesystem;
mod http;
mod http_types;
mod io;
mod ip_name_lookup;
mod network;
Expand Down Expand Up @@ -45,5 +48,8 @@ pub fn add_to_linker<T: Send>(
wasi::exit::add_to_linker(l, f)?;
wasi::environment::add_to_linker(l, f)?;
wasi::environment_preopens::add_to_linker(l, f)?;
wasi::types::add_to_linker(l, f)?;
wasi::default_outgoing_http::add_to_linker(l, f)?;
wasi::http::add_to_linker(l, f)?;
Ok(())
}
3 changes: 3 additions & 0 deletions verify/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ fn main() -> Result<()> {
&& i.module != "environment-preopens"
&& i.module != "exit"
&& i.module != "stderr"
&& i.module != "types"
&& i.module != "incoming-handler"
&& i.module != "outgoing-handler"
&& i.module != "canonical_abi"
&& i.module != "__main_module__"
{
Expand Down
2 changes: 1 addition & 1 deletion wasi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
publish = false

[dependencies]
wit-bindgen = { workspace = true, default-features = true }
wit-bindgen = { workspace = true, features = ["macros", "realloc"] }

[lib]
crate-type = ["lib"]
2 changes: 2 additions & 0 deletions wit/command.wit
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ default world command {
import random: random.random
import poll: poll.poll
import streams: io.streams
import default-outgoing-HTTP: http.outgoing-handler
import HTTP: http.incoming-handler
import environment: pkg.environment
import environment-preopens: pkg.environment-preopens
import exit: pkg.exit
Expand Down
24 changes: 24 additions & 0 deletions wit/deps/http/incoming-handler.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// The `wasi:http/incoming-handler` interface is meant to be exported by
// components and called by the host in response to a new incoming HTTP
// response.
//
// NOTE: in Preview3, this interface will be merged with
// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface
// that takes a `request` parameter and returns a `response` result.
//
default interface incoming-handler {
use pkg.types.{incoming-request, response-outparam}

// The `handle` function takes an outparam instead of returning its response
// so that the component may stream its response while streaming any other
// request or response bodies. The callee MUST write a response to the
// `response-out` and then finish the response before returning. The `handle`
// function is allowed to continue execution after finishing the response's
// output stream. While this post-response execution is taken off the
// critical path, since there is no return value, there is no way to report
// its success or failure.
handle: func(
request: incoming-request,
response-out: response-outparam
)
}
18 changes: 18 additions & 0 deletions wit/deps/http/outgoing-handler.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// The `wasi:http/outgoing-handler` interface is meant to be imported by
// components and implemented by the host.
//
// NOTE: in Preview3, this interface will be merged with
// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface
// that takes a `request` parameter and returns a `response` result.
//
default interface outgoing-handler {
use pkg.types.{outgoing-request, request-options, future-incoming-response}

// The parameter and result types of the `handle` function allow the caller
// to concurrently stream the bodies of the outgoing request and the incoming
// response.
handle: func(
request: outgoing-request,
options: option<request-options>
) -> future-incoming-response
}
Loading