Compare commits

..

2 commits

Author SHA1 Message Date
11db47b005
chore: update readme 2024-11-18 14:21:07 +11:00
f4b4d6a02d
refactor: use error macro 2024-11-18 14:20:51 +11:00
6 changed files with 16 additions and 12 deletions

View file

@ -1,7 +1,3 @@
# 1.1.2 / 2025-03-04
- Remove unused enum member
- Bump lucide vendored dependency to `16a18f79`
# 1.1.1
- Remove caching for `/info` (and all non-Bytes responses)
- Extract error function to a macro

View file

@ -20,6 +20,8 @@ If you are deploying to production, you can provide a directory path in the firs
Only `.svg` files will be read from that directory. The server's default port is `7878`, although this can be configured with the `PORT` environment variable.
It is recommended to place a reverse proxy in front of luciders to provide caching support, response compression and other optimisations that are out of scope for this project.
# Docker
You can build and run this project with Docker. The Dockerfile is configured to use the submodule for the icons. To build the image:

View file

@ -1,9 +1,8 @@
use crate::{
http::{
error, http::{
requests::{Request, RequestStatus, Url},
responses::{Body, Response, UnitOrBoxedError},
},
threads::ThreadPool,
}, threads::ThreadPool
};
use std::{
collections::HashMap,
@ -65,7 +64,7 @@ impl Handlers {
RequestStatus::Ok(req) => req,
RequestStatus::MalformedHTTP(stream) => {
stream.shutdown(Shutdown::Both).unwrap_or_else(|_| {
eprintln!("Failed to close malformed HTTP stream")
error!("Failed to shutdown malformed HTTP stream")
});
continue;
}

View file

@ -3,6 +3,7 @@ use std::{error::Error, io::prelude::*, net::TcpStream};
use super::requests::Request;
pub enum Body {
String(String),
Static(&'static str),
Bytes(Vec<u8>, &'static str),
}
@ -56,6 +57,7 @@ fn send_response(mut stream: TcpStream, status: u16, body: Body) -> UnitOrBoxedE
response.push_str(&format!(
"Content-Length: {}\r\n",
match &body {
Body::String(s) => s.len(),
Body::Static(s) => s.len(),
Body::Bytes(b, _) => b.len(),
}
@ -66,11 +68,16 @@ fn send_response(mut stream: TcpStream, status: u16, body: Body) -> UnitOrBoxedE
response.push_str("Cache-Control: immutable, public, max-age=604800\r\n");
}
Body::Static(_) => response.push_str("Content-Type: text/plain; charset=utf-8\r\n"),
_ => {}
}
response.push_str("\r\n");
// Body
if let Body::Static(s) = &body { response.push_str(s) }
match &body {
Body::String(s) => response.push_str(s),
Body::Static(s) => response.push_str(s),
_ => {}
}
match stream.write(response.as_bytes()) {
Ok(_) => {}

View file

@ -133,7 +133,7 @@ fn main() {
}
}
if req.url.query.contains_key("discord_compatibility") {
if let Some(_) = req.url.query.get("discord_compatibility") {
padding = 8;
}
@ -162,7 +162,7 @@ fn main() {
icon_string = icon_string.replace("currentColor", svg_stroke);
let mut backwards_compatibility = false;
if req.url.query.contains_key("backwards_compatibility") {
if let Some(_) = req.url.query.get("backwards_compatibility") {
backwards_compatibility = true;
// Icons were 80x80 plus 8px of padding; Icons start at 24x24 now so: 80 - 8 = 72, 72 / 24 = 3 therefore scale is 3x.
scale = 3;

2
vendor/lucide vendored

@ -1 +1 @@
Subproject commit 16a18f790881adc6f44767edac29bfc2b42b8dc5
Subproject commit 11b95f883a089f8596f85200298e01558b5db877