aboutsummaryrefslogtreecommitdiff
path: root/src/proxy.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/proxy.rs')
-rw-r--r--src/proxy.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/proxy.rs b/src/proxy.rs
index 2798df3..befb35b 100644
--- a/src/proxy.rs
+++ b/src/proxy.rs
@@ -42,7 +42,7 @@ use std::thread::{sleep, spawn, JoinHandle};
use std::time::Duration;
use crate::configuration::Proxy;
-use crate::middleware::MIDDLEWARE;
+use crate::middleware::{SERVER_MIDDLEWARE, CLIENT_MIDDLEWARE};
/// A proxy server that listens for plaintext connections and forwards them
/// via TLS.
@@ -229,7 +229,7 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
let mut command = buffer[..bytes_read].to_vec();
- for middleware in MIDDLEWARE {
+ for middleware in CLIENT_MIDDLEWARE {
command = middleware(&command);
}
@@ -242,7 +242,7 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
// Lock the TLS stream and write the data to server
match tls_stream_clone.lock() {
Ok(mut tls_guard) => {
- if let Err(error) = tls_guard.write_all(&buffer[..bytes_read]) {
+ if let Err(error) = tls_guard.write_all(&command) {
debug!(">>> Error writing to server: {error}");
break;
}
@@ -286,14 +286,20 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
}
};
- let debug_str = String::from_utf8_lossy(&buffer[..bytes_read])
+ let mut command = buffer[..bytes_read].to_vec();
+
+ for middleware in SERVER_MIDDLEWARE {
+ command = middleware(&command);
+ }
+
+ let debug_str = String::from_utf8_lossy(&command)
.replace('\n', "\\n")
.replace('\r', "\\r")
.replace('\t', "\\t");
debug!("<<< {}", debug_str);
// Write decrypted data to client
- if client_writer.write_all(&buffer[..bytes_read]).is_err() {
+ if client_writer.write_all(&command).is_err() {
debug!("<<< ERR");
break;
}