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