Skip to content

Commit 51631f7

Browse files
committed
Update proxer-cli to version 0.3.5 and refactor error logging
- Bump version of `proxer-cli` in `Cargo.toml` and `Cargo.lock` from 0.3.4 to 0.3.5. - Refactor error logging in `src/server/proxy.rs` to use a new `tracing_error` utility function for improved readability and consistency in error messages.
1 parent 5443bf0 commit 51631f7

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "proxer-cli"
3-
version = "0.3.4"
3+
version = "0.3.5"
44
edition = "2021"
55
authors = ["doroved"]
66
description = "Proxy TCP traffic on macOS with domain filtering."

src/server/proxy.rs

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

33
use super::ProxyConfig;
44
use crate::server::tunnel::{tunnel_direct, tunnel_via_proxy};
5+
use crate::server::utils::tracing_error;
56

67
use bytes::Bytes;
78
use http::{Method, Request, Response};
@@ -29,21 +30,19 @@ pub async fn handle_request(
2930
if let Err(e) =
3031
tunnel_via_proxy(upgraded, &addr, proxy, &filter_name).await
3132
{
32-
tracing::error!(
33-
"\x1B[31m{addr} → PROXY connection error: {e}\x1B[0m"
34-
);
33+
tracing_error(&format!("{addr} → PROXY connection error: {e}"));
3534
};
3635
} else if let Err(e) = tunnel_direct(upgraded, &addr).await {
37-
tracing::error!("\x1B[31m{addr} → DIRECT connection error: {e}\x1B[0m");
36+
tracing_error(&format!("{addr} → DIRECT connection error: {e}"));
3837
}
3938
}
40-
Err(e) => tracing::error!("\x1B[31m{addr} → UPGRADE error: {e}\x1B[0m"),
39+
Err(e) => tracing_error(&format!("{addr} → UPGRADE error: {e}")),
4140
}
4241
});
4342

4443
Ok(Response::new(empty()))
4544
} else {
46-
tracing::error!("CONNECT host is not socket addr: {:?}", req.uri());
45+
tracing_error(&format!("CONNECT host is not socket addr: {:?}", req.uri()));
4746
let mut resp = Response::new(full("CONNECT must be to a socket address"));
4847
*resp.status_mut() = http::StatusCode::BAD_REQUEST;
4948

@@ -68,15 +67,16 @@ pub async fn handle_request(
6867

6968
tokio::spawn(async move {
7069
if let Err(err) = conn.await {
71-
tracing::error!("\x1B[31mConnection failed: {:?}\x1B[0m", err);
70+
tracing_error(&format!("Connection failed: {:?}", err));
7271
}
7372
});
7473

7574
let resp = sender.send_request(req).await?;
7675
Ok(resp.map(|b| b.boxed()))
7776
}
78-
Err(e) => {
79-
tracing::error!("\x1B[31m{host}:{port} → Failed to connect: {:?}\x1B[0m", e);
77+
Err(err) => {
78+
tracing_error(&format!("{host}:{port} → Failed to connect: {:?}", err));
79+
8080
let mut resp = Response::new(full("Failed to connect to host"));
8181
*resp.status_mut() = http::StatusCode::BAD_GATEWAY;
8282

src/server/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ pub fn terminate_proxer() {
1515
"Failed to execute `kill $(pgrep proxer-cli)` command to terminate proxer processes",
1616
);
1717
}
18+
19+
pub fn tracing_error(message: &str) {
20+
tracing::error!("\x1B[31m{message}\x1B[0m");
21+
}

0 commit comments

Comments
 (0)