mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 01:15:42 -06:00
feat: add Server header middleware, bump version to v0.4.0
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1809,7 +1809,7 @@ version = "0.1.1"
|
||||
|
||||
[[package]]
|
||||
name = "pacman-server"
|
||||
version = "0.3.2"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "pacman-server"
|
||||
version = "0.3.2"
|
||||
version = "0.4.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version = "1.86.0"
|
||||
|
||||
@@ -7,12 +7,20 @@ This crate is a webserver that hosts an OAuth login and leaderboard API for the
|
||||
## Features
|
||||
|
||||
- [x] Axum Webserver
|
||||
- [x] Health Check
|
||||
- [ ] Inbound Rate Limiting
|
||||
- [ ] Outbound Rate Limiting
|
||||
- [ ] Provider Circuit Breaker
|
||||
- [x] Database
|
||||
- [x] OAuth
|
||||
- [x] Discord
|
||||
- [x] GitHub
|
||||
- [ ] Google (?)
|
||||
- [ ] Leaderboard API
|
||||
- [ ] Google
|
||||
- [ ] Leaderboard
|
||||
- [ ] Score Submission
|
||||
- [ ] Score Listings
|
||||
- [ ] Pagination
|
||||
- [ ] Global / Daily
|
||||
- [ ] Name Restrictions & Flagging
|
||||
- [ ] Avatars
|
||||
- [ ] 8-bit Conversion
|
||||
|
||||
@@ -19,6 +19,9 @@ use tokio::signal::unix::{signal, SignalKind};
|
||||
use tokio::sync::{watch, Notify};
|
||||
use tracing::{info, trace, warn};
|
||||
|
||||
// Constant value for the Server header: "<crate>/<version>"
|
||||
const SERVER_HEADER_VALUE: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Load environment variables
|
||||
@@ -60,7 +63,8 @@ async fn main() {
|
||||
.route("/logout", get(routes::logout_handler))
|
||||
.route("/profile", get(routes::profile_handler))
|
||||
.with_state(app_state.clone())
|
||||
.layer(CookieLayer::default());
|
||||
.layer(CookieLayer::default())
|
||||
.layer(axum::middleware::from_fn(inject_server_header));
|
||||
|
||||
info!(%addr, "Starting HTTP server bind");
|
||||
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
||||
@@ -172,3 +176,15 @@ async fn shutdown_signal() -> Instant {
|
||||
_ = sigterm => { Instant::now() }
|
||||
}
|
||||
}
|
||||
|
||||
async fn inject_server_header(
|
||||
req: axum::http::Request<axum::body::Body>,
|
||||
next: axum::middleware::Next,
|
||||
) -> Result<axum::response::Response, axum::http::StatusCode> {
|
||||
let mut res = next.run(req).await;
|
||||
res.headers_mut().insert(
|
||||
axum::http::header::SERVER,
|
||||
axum::http::HeaderValue::from_static(SERVER_HEADER_VALUE),
|
||||
);
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user