Skip to content

Commit e4443e1

Browse files
committed
clean up
1 parent dd4f2c5 commit e4443e1

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "api"
3-
version = "2.3.1"
3+
version = "2.3.2"
44
edition = "2024"
55

66
[profile.dev]
@@ -22,9 +22,8 @@ utoipa = { version = "5.3.1", features = ["axum_extras", "preserve_order", "chro
2222
utoipa-axum = "0.2.0"
2323
chrono = { version = "0.4.40", features = ["serde"] }
2424
indexmap = { version = "2.7.1", features = ["serde"] }
25-
tower-http = { version = "0.6.2", features = ["catch-panic", "trace", "cors", "normalize-path"] }
25+
tower-http = { version = "0.6.2", features = ["catch-panic", "cors", "normalize-path"] }
2626
sentry = { version = "0.37.0", default-features = false, features = ["rustls", "reqwest", "backtrace", "contexts", "debug-images", "panic"] }
27-
tracing = "0.1.41"
2827
reqwest = { version = "0.12.12", default-features = false, features = ["json", "rustls-tls"] }
2928
nestify = "0.3.3"
3029
sha2 = "0.10.8"

src/main.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ use axum::{
1919
use colored::Colorize;
2020
use sentry_tower::SentryHttpLayer;
2121
use serde_json::json;
22-
use sha1::Digest;
22+
use sha2::Digest;
2323
use std::{net::IpAddr, sync::Arc, time::Instant};
2424
use tokio::sync::RwLock;
2525
use tower::Layer;
2626
use tower_http::{
2727
catch_panic::CatchPanicLayer, cors::CorsLayer, normalize_path::NormalizePathLayer,
28-
trace::TraceLayer,
2928
};
3029
use utoipa::openapi::security::{ApiKey, ApiKeyValue, SecurityScheme};
3130
use utoipa_axum::router::OpenApiRouter;
@@ -50,7 +49,7 @@ fn handle_panic(_err: Box<dyn std::any::Any + Send + 'static>) -> Response<Body>
5049
.unwrap()
5150
}
5251

53-
fn handle_request(req: &Request<Body>, _span: &tracing::Span) {
52+
async fn handle_request(req: Request<Body>, next: Next) -> Result<Response, StatusCode> {
5453
let ip = extract_ip(req.headers())
5554
.map(|ip| ip.to_string())
5655
.unwrap_or_else(|| "unknown".to_string());
@@ -70,13 +69,15 @@ fn handle_request(req: &Request<Body>, _span: &tracing::Span) {
7069
format!("({})", ip).bright_black(),
7170
),
7271
);
72+
73+
Ok(next.run(req).await)
7374
}
7475

7576
async fn handle_etag(req: Request, next: Next) -> Result<Response, StatusCode> {
7677
let if_none_match = req.headers().get("If-None-Match").cloned();
7778

7879
let response = next.run(req).await;
79-
let mut hash = sha1::Sha1::new();
80+
let mut hash = sha2::Sha256::new();
8081

8182
let (mut parts, body) = response.into_parts();
8283
let body_bytes = axum::body::to_bytes(body, usize::MAX).await.unwrap();
@@ -202,7 +203,7 @@ async fn main() {
202203
})
203204
.layer(CatchPanicLayer::custom(handle_panic))
204205
.layer(CorsLayer::very_permissive())
205-
.layer(TraceLayer::new_for_http().on_request(handle_request))
206+
.layer(axum::middleware::from_fn(handle_request))
206207
.route_layer(axum::middleware::from_fn(handle_etag))
207208
.route_layer(SentryHttpLayer::with_transaction())
208209
.with_state(state.clone());

0 commit comments

Comments
 (0)