-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasm): update component to use wasip2 target
Signed-off-by: Brooks Townsend <[email protected]> feat(wasm): update component to use wasip2 target Signed-off-by: Brooks Townsend <[email protected]>
- Loading branch information
1 parent
8f35cf8
commit ca1cdb8
Showing
47 changed files
with
74 additions
and
2,944 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,52 @@ | ||
wit_bindgen::generate!(); | ||
|
||
use exports::wasi::http::incoming_handler::Guest; | ||
use wasi::http::types::*; | ||
use wasi::{ | ||
http::types::{Fields, IncomingRequest, OutgoingBody, OutgoingResponse, ResponseOutparam}, | ||
io::streams::{InputStream, OutputStream, StreamError}, | ||
}; | ||
|
||
#[allow(unused)] | ||
struct ReqwestComponent; | ||
|
||
impl Guest for ReqwestComponent { | ||
impl wasi::exports::http::incoming_handler::Guest for ReqwestComponent { | ||
fn handle(_request: IncomingRequest, response_out: ResponseOutparam) { | ||
let response = OutgoingResponse::new(Fields::new()); | ||
response.set_status_code(200).unwrap(); | ||
let response_body = response.body().unwrap(); | ||
let response_body = response | ||
.body() | ||
.expect("should be able to get response body"); | ||
ResponseOutparam::set(response_out, Ok(response)); | ||
|
||
let exampledotcom = reqwest::Client::new().get("http://example.com").send(); | ||
let response = futures::executor::block_on(exampledotcom).expect("should get response"); | ||
let bytes = futures::executor::block_on(response.bytes()).expect("should get bytes"); | ||
let response = | ||
futures::executor::block_on(reqwest::Client::new().get("https://hyper.rs").send()) | ||
.expect("should get response bytes"); | ||
let incoming_body = response.bytes_stream().expect("should get incoming body"); | ||
let stream = incoming_body.stream().expect("should get bytes stream"); | ||
stream_input_to_output( | ||
stream, | ||
response_body | ||
.write() | ||
.expect("should be able to write to response body"), | ||
) | ||
.expect("should be able to stream input to output"); | ||
|
||
response_body | ||
.write() | ||
.unwrap() | ||
.blocking_write_and_flush(&bytes) | ||
.unwrap(); | ||
OutgoingBody::finish(response_body, None).expect("failed to finish response body"); | ||
} | ||
} | ||
|
||
export!(ReqwestComponent); | ||
pub fn stream_input_to_output(data: InputStream, out: OutputStream) -> Result<(), StreamError> { | ||
loop { | ||
match out.blocking_splice(&data, u64::MAX) { | ||
Ok(bytes_spliced) if bytes_spliced == 0 => return Ok(()), | ||
Ok(_) => {} | ||
Err(e) => match e { | ||
StreamError::Closed => { | ||
return Ok(()); | ||
} | ||
StreamError::LastOperationFailed(e) => { | ||
return Err(StreamError::LastOperationFailed(e)); | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
|
||
wasi::http::proxy::export!(ReqwestComponent); |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
examples/wasm_component/wit/deps/clocks/monotonic-clock.wit
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.