Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • codecraft/webserver
  • sorcaMriete/webserver
  • opnonmicgo/webserver
  • loposuezo/webserver
  • diufeYmike/webserver
  • contbuspecmi/webserver
  • mogamuboun/webserver
  • glabalwelre/webserver
8 results
Show changes
import csv
def generate_rust_enum(csv_file):
rust_enum = "use phf::phf_map;\n\nenum Mime {\n"
with open(csv_file, "r") as file:
csv_data = csv.reader(file)
next(csv_data) # Skip the header row
for row in csv_data:
if row[1] == "":
continue
if "DEPRECATED" in row[0]:
continue
name = format_enum_member(row[0:2])
rust_enum += f"\t{name},\n"
rust_enum += "}\n\n"
rust_enum += "impl std::fmt::Display for Mime {\n"
rust_enum += "\tfn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n"
rust_enum += "\t\tmatch self {\n"
with open(csv_file, "r") as file:
csv_data = csv.reader(file)
next(csv_data) # Skip the header row
for row in csv_data:
if row[1] == "":
continue
if "DEPRECATED" in row[0]:
continue
name = format_enum_member(row[0:2])
rust_enum += f'\t\t\tMime::{name} => write!(f, "{row[1]}"),\n'
rust_enum += "\t\t}\n\t}\n}\n\n"
rust_enum += "static MimeMap: phf::Map<&'static str, Mime> = phf_map! {\n"
with open(csv_file, "r") as file:
csv_data = csv.reader(file)
next(csv_data)
for row in csv_data:
if row[1] == "":
continue
if "DEPRECATED" in row[0]:
continue
key = row[1]
value = format_enum_member(row[0:2])
rust_enum += f'\t"{key}" => Mime::{value},\n'
rust_enum += "};"
return rust_enum
def format_enum_member(name):
prefix = "".join(name[1].split("/")[0:-1])
name = name[0].split("-")
words = []
parts = []
for part in name:
parts += part.split("+")
for part in parts:
words += part.split(".")
formatted_name = "".join(word.capitalize() for word in words)
if not formatted_name.startswith(prefix.capitalize()):
formatted_name = prefix.capitalize() + formatted_name
return formatted_name
# Usage example
csv_file = "mimes.csv"
rust_enum_code = generate_rust_enum(csv_file)
print(rust_enum_code)
......@@ -110,7 +110,7 @@ checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
[[package]]
name = "http"
version = "0.1.0"
version = "1.0.0"
dependencies = [
"phf",
"tokio",
......@@ -457,7 +457,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]]
name = "site"
version = "0.1.0"
version = "1.0.0"
dependencies = [
"http",
"tokio",
......
[package]
name = "site"
version = "0.1.0"
version = "1.0.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
......
use http::handling::{methods::Method, routes::{Route, Data}, request::Request, response::{Response, Outcome, Status}, file_handlers::NamedFile};
use http::handling::{
file_handlers::NamedFile,
methods::Method,
request::Request,
response::{Outcome, Response, Status},
routes::{Data, Route},
};
fn static_files_handler(request: Request<>, _data: Data) -> Outcome<Response, Status, Data> {
let response = static_files(request.uri.raw_string().unwrap());
fn static_files_handler(request: Request, _data: Data) -> Outcome<Response, Status, Data> {
let response = static_files(&request.uri.to_string());
let response = match response {
Ok(dat) => Response {
headers: vec![],
......@@ -19,19 +25,24 @@ fn static_files(path: &str) -> Result<NamedFile, Status> {
}
fn index_handler(_request: Request, _data: Data) -> Outcome<Response, Status, Data> {
Outcome::Success(Response { headers: vec![], cookies: None, status: None, body: Box::new(index()) })
Outcome::Success(Response {
headers: vec![],
cookies: None,
status: None,
body: Box::new(index()),
})
}
fn index() -> NamedFile {
NamedFile::open("templates/index.html".into()).unwrap()
NamedFile::open("../templates/index.html".into()).unwrap()
}
fn favicon_handler(_request: Request, _data: Data) -> Outcome<Response, Status, Data> {
let response = Response {
headers: vec![],
cookies: None,
cookies: None,
status: None,
body: Box::new(NamedFile::open("/assets/favicon.svg".into()).unwrap())
body: Box::new(NamedFile::open("/assets/favicon.svg".into()).unwrap()),
};
Outcome::Success(response)
}
......@@ -42,34 +53,34 @@ async fn main() {
format: None,
handler: index_handler,
name: Some("index"),
uri: "",
uri: "".try_into().unwrap(),
method: Method::Get,
rank: 0,
};
let static_route = Route {
let static_route = Route {
format: None,
handler: static_files_handler,
name: Some("static files"),
uri: "",
uri: "<file..>".try_into().unwrap(),
method: Method::Get,
rank: 0
rank: 0,
};
let favicon = Route {
format: None,
format: None,
handler: favicon_handler,
name: Some("favicon"),
uri: "favicon.ico",
uri: "favicon.ico".try_into().unwrap(),
method: Method::Get,
rank: 0
rank: 0,
};
// http::build("127.0.0.1:8000")
http::build("127.0.0.1:8443", "127.0.0.1:8080")
.await
.mount("/", vec![index_route, favicon])
.mount("/static", vec![static_route])
.mount("/static".try_into().unwrap(), vec![static_route])
.mount("/".try_into().unwrap(), vec![index_route, favicon])
.launch()
.await;
}
......@@ -8,7 +8,7 @@
<body>
<header>
<nav>
<div>LOGO</div>
<div><img src="/favicon.ico" alt="ICON" width="32" height="32" /></div>
<div>
<div>Dashboard</div>
<div>Books</div>
......
Name, format, asdf
vnd.motorola.video,video/vnd.motorola.video,[Tom_McGinty]
vnd.motorola.videop,video/vnd.motorola.videop,[Tom_McGinty]
vnd.mpegurl,video/vnd.mpegurl,[Heiko_Recktenwald]
vnd.ms-playready.media.pyv,video/vnd.ms-playready.media.pyv,[Steve_DiAcetis]
vnd.nokia.interleaved-multimedia,video/vnd.nokia.interleaved-multimedia,[Petteri_Kangaslampi]
vnd.nokia.mp4vr,video/vnd.nokia.mp4vr,[Miska_M._Hannuksela]
vnd.nokia.videovoip,video/vnd.nokia.videovoip,[Nokia]
vnd.objectvideo,video/vnd.objectvideo,[John_Clark]
vnd.radgamettools.bink,video/vnd.radgamettools.bink,[Henrik_Andersson]
vnd.radgamettools.smacker,video/vnd.radgamettools.smacker,[Henrik_Andersson]
vnd.sealed.mpeg1,video/vnd.sealed.mpeg1,[David_Petersen]
vnd.sealed.mpeg4,video/vnd.sealed.mpeg4,[David_Petersen]
vnd.sealed.swf,video/vnd.sealed.swf,[David_Petersen]
vnd.sealedmedia.softseal.mov,video/vnd.sealedmedia.softseal.mov,[David_Petersen]
vnd.uvvu.mp4,video/vnd.uvvu.mp4,[Michael_A_Dolan]
vnd.youtube.yt,video/vnd.youtube.yt,[Google]
vnd.vivo,video/vnd.vivo,[John_Wolfe]
VP8,video/VP8,[RFC7741]
VP9,video/VP9,[RFC-ietf-payload-vp9-16]
.
├── core
│ ├── codegen
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ ├── src
│ │ │ └── lib.rs
│ ├── html
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ └── src
│ │ └── lib.rs
│ └── http
│ ├── Cargo.lock
│ ├── Cargo.toml
│ └── src
│ ├── handlers
│ │ ├── file_handlers.rs
│ │ ├── handlers.rs
│ │ └── mod.rs
│ ├── lib.rs
│ ├── routing
│ │ ├── methods.rs
│ │ ├── mod.rs
│ │ └── routes.rs
│ ├── setup.rs
│ ├── threading.rs
│ └── utils
│ └── mod.rs
├── README.md
├── site
│ ├── 404.html
│ ├── Cargo.lock
│ ├── Cargo.toml
│ ├── hello.css
│ ├── img.jpg
│ ├── src
│ │ └── main.rs
│ ├── static
│ │ └── hello.html
│ └── target
│ └── CACHEDIR.TAG
└── tree.txt