maj-async-std #4

Merged
cadey merged 11 commits from maj-async-std into main 2020-07-28 01:36:02 +00:00
3 changed files with 14 additions and 5 deletions
Showing only changes of commit cd6ef8a516 - Show all commits

View File

@ -19,7 +19,7 @@ tokio-rustls = { version = "0.14", features = ["dangerous_configuration"], optio
webpki = { version = "0.21.0", optional = true }
webpki-roots = { version = "0.20", optional = true }
tokio = { version = "0.2", features = ["full"], optional = true }
async-tls = { version = "0.9.0", default-features = false, optional = true }
async-tls = { default-features = false, optional = true, git = "https://github.com/Xe/async-tls" }
async-std = { version = "1.6", optional = true }
log = "0.4"
url = "2"

View File

@ -1,5 +1,6 @@
use async_std::task;
use maj::{
gemini::Builder,
route, seg,
server::{Error, Handler as MajHandler, Request},
split, Response,
@ -97,8 +98,16 @@ async fn majc() -> Result<maj::Response, maj::server::Error> {
Ok(Response::gemini(msg.to_vec()))
}
async fn need_cert() -> Result<Response, Error> {
Ok(Response::need_cert("test"))
async fn need_cert(req: Request) -> Result<Response, Error> {
match req.certs {
None => Ok(Response::need_cert("test")),
Some(certs) => Ok(Response::render(
Builder::new()
.heading(1, "Cert test")
.text(format!("{:?}", certs))
.build(),
)),
}
}
#[async_trait::async_trait]
@ -117,7 +126,7 @@ impl MajHandler for Handler {
route!(req.url.path(), {
(/) => index().await;
(/"cert") => need_cert().await;
(/"cert") => need_cert(req).await;
(/"majc") => majc().await;
});

View File

@ -90,7 +90,7 @@ async fn handle_request(
let req = Request {
url: url,
certs: None,
certs: stream.peer_certificates(),
};
handle(h, req, &mut stream, addr).await;
}