added content-types

doctorpavel
Dawid J. Kubis 1 year ago
parent 7cf755b47b
commit 547d93cbb7

16
Cargo.lock generated

@ -81,9 +81,9 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-epoch" name = "crossbeam-epoch"
version = "0.9.14" version = "0.9.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"cfg-if", "cfg-if",
@ -94,9 +94,9 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.15" version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
] ]
@ -212,15 +212,15 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.18" version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]] [[package]]
name = "memoffset" name = "memoffset"
version = "0.8.0" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [ dependencies = [
"autocfg", "autocfg",
] ]

@ -8,9 +8,8 @@ use crate::post::{Post, Thread};
use std::io; use std::io;
use std::io::{BufRead, BufReader, Read, Write}; use std::io::{BufRead, BufReader, Read, Write};
use std::net::{SocketAddr, TcpListener, TcpStream}; use std::net::{TcpListener, TcpStream};
use std::path::PathBuf; use std::path::PathBuf;
use std::str;
use bincode::{deserialize, serialize}; use bincode::{deserialize, serialize};
use errors::DatabaseError; use errors::DatabaseError;
@ -37,6 +36,9 @@ struct Opt {
#[structopt(short, long, default_value = "data")] #[structopt(short, long, default_value = "data")]
database: PathBuf, database: PathBuf,
#[structopt(short, long, default_value = "999999999")]
max_id: u32,
} }
// get command line arguments and make them static // get command line arguments and make them static
@ -215,15 +217,23 @@ fn get(path: &str) -> Result<Response, HandlingError> {
.fold(String::from(""), |a, b| format!("{a}\n{b}")); .fold(String::from(""), |a, b| format!("{a}\n{b}"));
let c = content("index", &ops); let c = content("index", &ops);
Ok(Response::new(Status::Ok, vec![], c.into())) Ok(Response::new(
Status::Ok,
vec![("content-type", "text/html; charset=utf-8")],
c.into(),
))
} }
// TODO favicon.ico // TODO favicon.ico
"/css" => Ok(Response::new( "/css" => Ok(Response::new(
Status::Ok, Status::Ok,
vec![], vec![("content-type", "text/css; charset=utf-8")],
String::from(STYLE).into(), String::from(STYLE).into(),
)), )),
"/faq" => Ok(Response::new(Status::Ok, vec![], String::from(FAQ).into())), "/faq" => Ok(Response::new(
Status::Ok,
vec![("content-type", "text/html; charset=utf-8")],
String::from(FAQ).into(),
)),
"/favicon.ico" => Ok(Response::new( "/favicon.ico" => Ok(Response::new(
Status::Ok, Status::Ok,
vec![("content-type", "image/x-icon")], vec![("content-type", "image/x-icon")],
@ -250,7 +260,11 @@ fn get(path: &str) -> Result<Response, HandlingError> {
.iter() .iter()
.fold(String::from(""), |a, b| format!("{a}\n{b}")); .fold(String::from(""), |a, b| format!("{a}\n{b}"));
let c = content(&id.to_string(), &c); let c = content(&id.to_string(), &c);
Ok(Response::new(Status::Ok, vec![], c.into())) Ok(Response::new(
Status::Ok,
vec![("content-type", "text/html; charset=utf-8")],
c.into(),
))
} }
} }
} }

Loading…
Cancel
Save