maj-async-std #4
|
@ -5,7 +5,9 @@ use maj::{
|
|||
split, Response,
|
||||
};
|
||||
use rustls::internal::pemfile::{certs, rsa_private_keys};
|
||||
use rustls::{Certificate, NoClientAuth, PrivateKey, ServerConfig};
|
||||
use rustls::{
|
||||
AllowAnyAnonymousOrAuthenticatedClient, Certificate, PrivateKey, RootCertStore, ServerConfig,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufReader};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -62,7 +64,9 @@ fn main() -> Result<(), maj::server::Error> {
|
|||
opts.port
|
||||
);
|
||||
|
||||
let mut config = ServerConfig::new(NoClientAuth::new());
|
||||
let mut config = ServerConfig::new(AllowAnyAnonymousOrAuthenticatedClient::new(
|
||||
RootCertStore::empty(),
|
||||
));
|
||||
config
|
||||
.set_single_cert(certs, keys.remove(0))
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
|
||||
|
@ -83,16 +87,20 @@ struct Handler {
|
|||
hostname: String,
|
||||
}
|
||||
|
||||
fn index(_req: Request) -> Result<maj::Response, maj::server::Error> {
|
||||
async fn index() -> Result<maj::Response, maj::server::Error> {
|
||||
let msg = include_bytes!("index.gmi");
|
||||
Ok(Response::gemini(msg.to_vec()))
|
||||
}
|
||||
|
||||
fn majc(_req: Request) -> Result<maj::Response, maj::server::Error> {
|
||||
async fn majc() -> Result<maj::Response, maj::server::Error> {
|
||||
let msg = include_bytes!("majc.gmi");
|
||||
Ok(Response::gemini(msg.to_vec()))
|
||||
}
|
||||
|
||||
async fn need_cert() -> Result<Response, Error> {
|
||||
Ok(Response::need_cert("test"))
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MajHandler for Handler {
|
||||
async fn handle(&self, req: Request) -> Result<Response, Error> {
|
||||
|
@ -108,8 +116,9 @@ impl MajHandler for Handler {
|
|||
}
|
||||
|
||||
route!(req.url.path(), {
|
||||
(/) => index(req);
|
||||
(/"majc") => majc(req);
|
||||
(/) => index().await;
|
||||
(/"cert") => need_cert().await;
|
||||
(/"majc") => majc().await;
|
||||
});
|
||||
|
||||
Ok(Response::not_found())
|
||||
|
|
|
@ -53,6 +53,22 @@ impl Response {
|
|||
body: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn input<T: Into<String>>(msg: T) -> Response {
|
||||
Response {
|
||||
status: StatusCode::Input,
|
||||
meta: msg.into(),
|
||||
body: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn need_cert<T: Into<String>>(msg: T) -> Response {
|
||||
Response {
|
||||
status: StatusCode::ClientCertificateRequired,
|
||||
meta: msg.into(),
|
||||
body: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The parser state.
|
||||
|
|
Loading…
Reference in New Issue