Skip to content

Commit

Permalink
Update proxer-cli to version 0.3.5 and refactor error logging
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
doroved committed Dec 18, 2024
1 parent 5443bf0 commit 51631f7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "proxer-cli"
version = "0.3.4"
version = "0.3.5"
edition = "2021"
authors = ["doroved"]
description = "Proxy TCP traffic on macOS with domain filtering."
Expand Down
18 changes: 9 additions & 9 deletions src/server/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use super::ProxyConfig;
use crate::server::tunnel::{tunnel_direct, tunnel_via_proxy};
use crate::server::utils::tracing_error;

use bytes::Bytes;
use http::{Method, Request, Response};
Expand Down Expand Up @@ -29,21 +30,19 @@ pub async fn handle_request(
if let Err(e) =
tunnel_via_proxy(upgraded, &addr, proxy, &filter_name).await
{
tracing::error!(
"\x1B[31m{addr} → PROXY connection error: {e}\x1B[0m"
);
tracing_error(&format!("{addr} → PROXY connection error: {e}"));
};
} else if let Err(e) = tunnel_direct(upgraded, &addr).await {
tracing::error!("\x1B[31m{addr} → DIRECT connection error: {e}\x1B[0m");
tracing_error(&format!("{addr} → DIRECT connection error: {e}"));
}
}
Err(e) => tracing::error!("\x1B[31m{addr} → UPGRADE error: {e}\x1B[0m"),
Err(e) => tracing_error(&format!("{addr} → UPGRADE error: {e}")),
}
});

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

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

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

let resp = sender.send_request(req).await?;
Ok(resp.map(|b| b.boxed()))
}
Err(e) => {
tracing::error!("\x1B[31m{host}:{port} → Failed to connect: {:?}\x1B[0m", e);
Err(err) => {
tracing_error(&format!("{host}:{port} → Failed to connect: {:?}", err));

let mut resp = Response::new(full("Failed to connect to host"));
*resp.status_mut() = http::StatusCode::BAD_GATEWAY;

Expand Down
4 changes: 4 additions & 0 deletions src/server/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ pub fn terminate_proxer() {
"Failed to execute `kill $(pgrep proxer-cli)` command to terminate proxer processes",
);
}

pub fn tracing_error(message: &str) {
tracing::error!("\x1B[31m{message}\x1B[0m");
}

0 comments on commit 51631f7

Please sign in to comment.