some error codes in handler

This commit is contained in:
Jan Wolff 2020-05-16 12:47:42 +02:00
parent 769affa1b6
commit 177d12b5b8
3 changed files with 24 additions and 7 deletions

View file

@ -1,6 +1,8 @@
mod server;
use std::path::Path;
fn main() {
let server = server::Server::new("gemini://localhost");
let wwwRoot = Path::new("/var/www/gemini/");
let server = server::Server::new("gemini://localhost", &wwwRoot);
server.serve();
}

View file

@ -1,7 +1,17 @@
use url::Url;
use crate::server::response;
use crate::server::ServerConfig;
use std::path::Path;
use url::Url;
pub fn handle(config: &ServerConfig, url: Url) -> Option<response::Response> {
Some(response::invalid_protocol())
if url.scheme() != "gemini" {
return Some(response::invalid_protocol());
}
let path = Path::new(url.path());
if !path.has_root() {
return Some(response::not_understood());
}
None
}

View file

@ -2,17 +2,19 @@ use crate::server::response::Response;
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod, SslStream};
use std::collections::HashMap;
use std::net::{SocketAddr, TcpListener, TcpStream};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::thread;
use std::vec::Vec;
use std::sync::Arc;
use url::Url;
pub mod response;
pub mod handler;
pub mod response;
#[derive(Clone)]
pub struct ServerConfig {
defaultHost: Url,
wwwRoot: PathBuf,
}
pub struct Server {
@ -21,8 +23,11 @@ pub struct Server {
}
impl Server {
pub fn new(host: &str) -> Server {
let config = ServerConfig{defaultHost: Url::parse(host).unwrap()};
pub fn new(host: &str, wwwRoot: &Path) -> Server {
let config = ServerConfig {
defaultHost: Url::parse(host).unwrap(),
wwwRoot: PathBuf::from(wwwRoot),
};
Server {
acceptor: build_acceptor(),