fix: do not cache non-Bytes

so docs & errors don't get cached
This commit is contained in:
Compositr 2024-11-04 22:07:57 +11:00
parent 9b20403cef
commit a3383084fb

View file

@ -51,7 +51,6 @@ fn send_response(mut stream: TcpStream, status: u16, body: Body) -> UnitOrBoxedE
// Headers
response.push_str("Server: luciders\r\n");
response.push_str("Cache-Control: immutable, public, max-age=604800\r\n");
// CORS
response.push_str("Access-Control-Allow-Origin: *\r\n");
response.push_str("Access-Control-Allow-Methods: GET\r\n");
@ -65,7 +64,8 @@ fn send_response(mut stream: TcpStream, status: u16, body: Body) -> UnitOrBoxedE
));
match &body {
Body::Bytes(_, content_type) => {
response.push_str(&format!("Content-Type: {}\r\n", content_type))
response.push_str(&format!("Content-Type: {}\r\n", content_type));
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"),
_ => {}