Changed util to conn
This commit is contained in:
@@ -8,9 +8,9 @@ use url::Url;
|
||||
|
||||
use crate::config;
|
||||
use crate::status;
|
||||
use crate::util;
|
||||
use crate::conn;
|
||||
|
||||
pub async fn cgi(mut con: util::Connection, path: PathBuf, url: Url) -> Result<(), io::Error> {
|
||||
pub async fn cgi(mut con: conn::Connection, path: PathBuf, url: Url) -> Result<(), io::Error> {
|
||||
let mut envs = HashMap::new();
|
||||
envs.insert("GEMINI_URL", url.as_str());
|
||||
envs.insert("SERVER_NAME", url.host_str().unwrap());
|
||||
|
||||
@@ -2,7 +2,6 @@ extern crate serde_derive;
|
||||
extern crate toml;
|
||||
use std::collections::HashMap;
|
||||
use toml::de::Error;
|
||||
// use serde_derive::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct Config {
|
||||
@@ -26,10 +25,16 @@ impl Config {
|
||||
let config: Config = toml::from_str(&fd).unwrap();
|
||||
return config;
|
||||
}
|
||||
pub fn to_map(&self) -> HashMap<String, String> {
|
||||
pub fn to_map(&self) -> HashMap<String, Server> {
|
||||
let mut map = HashMap::new();
|
||||
for srv in &self.server {
|
||||
map.insert(srv.hostname.clone(), srv.dir.clone());
|
||||
map.insert(srv.hostname.clone(), Server {
|
||||
hostname: srv.hostname.clone(),
|
||||
dir: srv.dir.clone(),
|
||||
key: srv.key.clone(),
|
||||
cert: srv.cert.clone(),
|
||||
cgi: srv.cgi.clone()
|
||||
});
|
||||
}
|
||||
map
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ mod cgi;
|
||||
mod config;
|
||||
mod status;
|
||||
mod tls;
|
||||
mod util;
|
||||
mod conn;
|
||||
|
||||
fn get_mime(path: &PathBuf) -> String {
|
||||
let mut mime = "text/gemini";
|
||||
@@ -51,7 +51,7 @@ fn get_mime(path: &PathBuf) -> String {
|
||||
mime.to_string()
|
||||
}
|
||||
|
||||
async fn get_binary(mut con: util::Connection, path:PathBuf, meta: String) -> io::Result<()> {
|
||||
async fn get_binary(mut con: conn::Connection, path:PathBuf, meta: String) -> io::Result<()> {
|
||||
let fd = File::open(path)?;
|
||||
let mut reader = BufReader::with_capacity(1024*1024,fd);
|
||||
con.send_status(status::Status::Success, &meta).await?;
|
||||
@@ -88,7 +88,7 @@ fn get_content(path: PathBuf, u: url::Url) -> Result<String, io::Error> {
|
||||
return Ok(list);
|
||||
}
|
||||
|
||||
async fn handle_connection(mut con: util::Connection) -> Result<(), io::Error> {
|
||||
async fn handle_connection(mut con: conn::Connection) -> Result<(), io::Error> {
|
||||
let now: DateTime<Utc> = Utc::now();
|
||||
println!("{} New Connection: {}", now, con.peer_addr);
|
||||
let mut buffer = [0; 512];
|
||||
@@ -209,7 +209,7 @@ fn main() -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
let con = util::Connection {
|
||||
let con = conn::Connection {
|
||||
stream,
|
||||
peer_addr,
|
||||
hostname,
|
||||
|
||||
Reference in New Issue
Block a user