Skip to content

Commit

Permalink
update main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
kfatyuip committed Jul 22, 2024
1 parent 1c87a99 commit c3bb122
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tsr::{
use chrono::{DateTime, Utc};
use clap::Parser;
use mime::Mime;
use std::{collections::HashMap, env, error::Error, ops::Deref, path::Path};
use std::{collections::HashMap, env, error::Error, io, ops::Deref, path::Path};

#[cfg(feature = "log")]
use log::log;
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<'a> Response<'a> {
}
}

async fn handle_connection(mut stream: TcpStream) -> Result<(i32, String), Box<dyn Error>> {
async fn handle_connection(mut stream: TcpStream) -> io::Result<(i32, String)> {
let config = CONFIG.deref();

let mut response: Response = Response {
Expand Down Expand Up @@ -112,7 +112,9 @@ async fn handle_connection(mut stream: TcpStream) -> Result<(i32, String), Box<d
} else if parts[0].trim() != "GET" {
response.status_code = 501;
} else if let Some(location) = &req.split_whitespace().nth(1) {
let location: String = urlencoding::decode(location.trim_start_matches('/'))?.into();
let location: String = urlencoding::decode(location.trim_start_matches('/'))
.unwrap_or_default()
.into();

response.version = parts[2];
let mut path = config.server.root.join(location.split('?').next().unwrap());
Expand Down

0 comments on commit c3bb122

Please sign in to comment.