Cleanup code
This commit is contained in:
parent
715aed3a3c
commit
13fdef8053
2
README.md
Normal file
2
README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Proxy saver
|
||||
Proxify HTTP request to HTTPS upstream, saving requests and responses.
|
34
src/main.rs
34
src/main.rs
@ -6,12 +6,10 @@ use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::pin;
|
||||
use tokio::time::interval;
|
||||
use tokio_rustls::TlsConnector;
|
||||
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
|
||||
|
||||
@ -36,8 +34,6 @@ struct Args {
|
||||
storage_path: String,
|
||||
}
|
||||
|
||||
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
||||
|
||||
/// Get the current time since epoch
|
||||
pub fn time() -> u64 {
|
||||
SystemTime::now()
|
||||
@ -78,12 +74,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut req_file = OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.open(Path::new(&args.storage_path).join(format!("req-{base_file_name}")))
|
||||
.open(Path::new(&args.storage_path).join(format!("{base_file_name}-req")))
|
||||
.expect("Failed to create req file");
|
||||
let mut res_file = OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.open(Path::new(&args.storage_path).join(format!("res-{base_file_name}")))
|
||||
.open(Path::new(&args.storage_path).join(format!("{base_file_name}-res")))
|
||||
.expect("Failed to create req file");
|
||||
|
||||
let mut root_cert_store = RootCertStore::empty();
|
||||
@ -104,17 +100,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let (mut client_read, mut client_write) = client_socket.split();
|
||||
|
||||
let mut interval = interval(HEARTBEAT_INTERVAL);
|
||||
let mut buf_client = [0u8; 1024];
|
||||
let mut buf_server = [0u8; 1024];
|
||||
|
||||
let mut modified_headers = false;
|
||||
|
||||
loop {
|
||||
let tick = interval.tick();
|
||||
// required for select()
|
||||
pin!(tick);
|
||||
|
||||
tokio::select! {
|
||||
count = client_read.read(&mut buf_client) => {
|
||||
let count = match count{ Ok(count) => count, Err(e) => {
|
||||
@ -180,16 +171,15 @@ fn manipulate_headers(buff: &[u8], host: &str) -> Vec<u8> {
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/*// Work line per line
|
||||
buff.to_vec()
|
||||
.split(&b'\n')
|
||||
.map(|l| {
|
||||
if l.starts_with(b"Host:") {
|
||||
format!("Host: {host}\r")
|
||||
} else {
|
||||
l.to_owned()
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::Args;
|
||||
|
||||
#[test]
|
||||
fn verify_cli() {
|
||||
use clap::CommandFactory;
|
||||
Args::command().debug_assert()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<u8>>()*/
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user