Skip to content

Commit 194b1a2

Browse files
committed
init routes
1 parent 5aba90a commit 194b1a2

File tree

3 files changed

+13
-101
lines changed

3 files changed

+13
-101
lines changed

Cargo.lock

Lines changed: 5 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@ package = "component:rust-wasi-hello"
1313
# `get-environment` or other things not present in the proxy world.
1414
proxy = true
1515

16-
[package.metadata.component.dependencies]
17-
18-
[package.metadata.component.target]
19-
20-
[package.metadata.component.target.dependencies]
21-
"wasi:http" = { path = "wit/deps/http" }
22-
"wasi:clocks" = { path = "wit/deps/clocks" }
23-
"wasi:io" = { path = "wit/deps/io" }
24-
"wasi:random" = { path = "wit/deps/random" }
25-
"wasi:cli" = { path = "wit/deps/cli" }
26-
"wasi:filesystem" = { path = "wit/deps/filesystem" }
27-
"wasi:sockets" = { path = "wit/deps/sockets" }
28-
29-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
30-
3116
[dependencies]
32-
url = "2.5.2"
3317
wasi = "0.13.2"
34-
wit-bindgen-rt = { version = "0.24.0", features = ["bitflags"] }
18+
wit-bindgen-rt = { version = "0.30.0", features = ["bitflags"] }

src/lib.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use url::Url;
21
pub use wasi::http::types::{
32
Fields, IncomingRequest, OutgoingBody, OutgoingResponse, ResponseOutparam,
43
};
@@ -8,16 +7,12 @@ wasi::http::proxy::export!(Component);
87

98
impl wasi::exports::http::incoming_handler::Guest for Component {
109
fn handle(req: IncomingRequest, outparam: ResponseOutparam) {
11-
let url = req.path_with_query().unwrap();
12-
let url = Url::parse(&url).expect("could not parse the URL");
13-
http_home(req, outparam);
14-
// dbg!(&url);
15-
// match url.path() {
16-
// "/wait" => http_wait(req, outparam),
17-
// // "/echo" => {} // TODO
18-
// // "/host" => {} // TODO
19-
// "/" | _ => http_home(req, outparam),
20-
// }
10+
match req.path_with_query().unwrap().as_str() {
11+
"/wait" => http_wait(req, outparam),
12+
// "/echo" => {} // TODO
13+
// "/host" => {} // TODO
14+
"/" | _ => http_home(req, outparam),
15+
}
2116
}
2217
}
2318

@@ -56,7 +51,7 @@ fn http_wait(_req: IncomingRequest, outparam: ResponseOutparam) {
5651
ResponseOutparam::set(outparam, Ok(res));
5752

5853
let out = body.write().expect("outgoing stream");
59-
let msg = format!("slept for {elapsed} millis");
54+
let msg = format!("slept for {elapsed} millis\n");
6055
out.blocking_write_and_flush(msg.as_bytes())
6156
.expect("writing response");
6257

0 commit comments

Comments
 (0)