Skip to content

Commit 9905042

Browse files
committed
Log incoming HTTP headers in WebSocket handlers
Added logging of all incoming HTTP headers in both mixed_handler and v2_mixed_handler functions for improved request tracing and debugging. Each header is logged with its name and value, handling non-UTF8 values gracefully.
1 parent 0b00e34 commit 9905042

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/services/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::sync::Arc;
22

33
use axum::{
44
extract::{Path, Query, WebSocketUpgrade},
5+
http::HeaderMap,
56
response::{IntoResponse, Response},
67
Extension,
78
};
@@ -22,10 +23,16 @@ pub struct ConnectQueryParams {
2223
pub async fn mixed_handler(
2324
Extension(pool): Extension<Arc<ws::WsSetting>>,
2425
Extension(record_setting): Extension<Arc<ws_record::WsRecordSetting>>,
26+
headers: HeaderMap,
2527
ws: WebSocketUpgrade,
2628
Path(id): Path<String>,
2729
Query(params): Query<ConnectQueryParams>,
2830
) -> Response {
31+
for (name, value) in headers.iter() {
32+
let value = value.to_str().unwrap_or("<non-utf8>");
33+
log::info!("Incoming header: {}: {}", name, value);
34+
}
35+
2936
if params.record {
3037
ws_record::ws_handler(Extension(record_setting), ws, Path(id))
3138
.await
@@ -47,10 +54,16 @@ pub async fn mixed_handler(
4754
pub async fn v2_mixed_handler(
4855
Extension(record_setting): Extension<Arc<ws_record::WsRecordSetting>>,
4956
Extension(pool): Extension<Arc<ws::stable::StableWsSetting>>,
57+
headers: HeaderMap,
5058
ws: WebSocketUpgrade,
5159
Path(id): Path<String>,
5260
Query(params): Query<ConnectQueryParams>,
5361
) -> Response {
62+
for (name, value) in headers.iter() {
63+
let value = value.to_str().unwrap_or("<non-utf8>");
64+
log::info!("Incoming header: {}: {}", name, value);
65+
}
66+
5467
if params.record {
5568
ws_record::ws_handler(Extension(record_setting), ws, Path(id))
5669
.await

0 commit comments

Comments
 (0)