mirror of
https://github.com/mikedilger/chorus.git
synced 2026-08-31 07:31:01 +00:00
Log user agent
This commit is contained in:
parent
5e7c1c386e
commit
c0f77caf58
16
src/main.rs
16
src/main.rs
@ -230,6 +230,11 @@ async fn handle_http_request(
|
|||||||
peer: SocketAddr,
|
peer: SocketAddr,
|
||||||
mut request: Request<Body>,
|
mut request: Request<Body>,
|
||||||
) -> Result<Response<Body>, Error> {
|
) -> Result<Response<Body>, Error> {
|
||||||
|
let ua = match request.headers().get("user-agent") {
|
||||||
|
Some(ua) => ua.to_str().unwrap_or("NON-UTF8-HEADER").to_owned(),
|
||||||
|
None => "".to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
if hyper_tungstenite::is_upgrade_request(&request) {
|
if hyper_tungstenite::is_upgrade_request(&request) {
|
||||||
let web_socket_config = WebSocketConfig {
|
let web_socket_config = WebSocketConfig {
|
||||||
max_write_buffer_size: 1024 * 1024, // 1 MB
|
max_write_buffer_size: 1024 * 1024, // 1 MB
|
||||||
@ -259,9 +264,10 @@ async fn handle_http_request(
|
|||||||
let old_num_websockets = GLOBALS.num_clients.fetch_add(1, Ordering::SeqCst);
|
let old_num_websockets = GLOBALS.num_clients.fetch_add(1, Ordering::SeqCst);
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"{}: websocket started (making {} active websockets)",
|
"{}: TOTAL={}, Connection: {}",
|
||||||
peer,
|
peer,
|
||||||
old_num_websockets + 1
|
old_num_websockets + 1,
|
||||||
|
ua
|
||||||
);
|
);
|
||||||
|
|
||||||
// Everybody gets a 4-second ban on disconnect to prevent
|
// Everybody gets a 4-second ban on disconnect to prevent
|
||||||
@ -290,11 +296,7 @@ async fn handle_http_request(
|
|||||||
// Decrement count of active websockets
|
// Decrement count of active websockets
|
||||||
let old_num_websockets = GLOBALS.num_clients.fetch_sub(1, Ordering::SeqCst);
|
let old_num_websockets = GLOBALS.num_clients.fetch_sub(1, Ordering::SeqCst);
|
||||||
|
|
||||||
log::info!(
|
log::info!("{}: TOTAL={}, Disconnection", peer, old_num_websockets - 1);
|
||||||
"{}: websocket ended (making {} active websockets)",
|
|
||||||
peer,
|
|
||||||
old_num_websockets - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
// Ban for the appropriate duration
|
// Ban for the appropriate duration
|
||||||
Globals::ban(peer.ip(), ban_seconds).await;
|
Globals::ban(peer.ip(), ban_seconds).await;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user