Browse Source

made changes so arguments will accept Option<&T> instead of &Option<T>

pull/22/head
KaranGauswami 10 months ago
parent
commit
149c4b25fb
No known key found for this signature in database GPG Key ID: A4D57BC9D0772045
  1. 9
      src/main.rs
  2. 10
      src/proxy/mod.rs
  3. 2
      tests/proxy.rs

9
src/main.rs

@ -68,7 +68,14 @@ async fn main() -> Result<()> {
loop {
let (stream, _) = listener.accept().await?;
tokio::task::spawn(async move {
if let Err(e) = proxy_request(stream, socks_addr, auth_details, allowed_domains).await {
if let Err(e) = proxy_request(
stream,
socks_addr,
auth_details.as_ref(),
allowed_domains.as_ref(),
)
.await
{
error!("Error proxying request: {}", e);
}
});

10
src/proxy/mod.rs

@ -24,8 +24,8 @@ use hyper::server::conn::http1;
async fn proxy(
req: Request<hyper::body::Incoming>,
socks_addr: SocketAddr,
auth: &'static Option<Auth>,
allowed_domains: &Option<Vec<String>>,
auth: Option<&'static Auth>,
allowed_domains: Option<&'static Vec<String>>,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>> {
let uri = req.uri();
let method = req.method();
@ -120,7 +120,7 @@ async fn tunnel(
upgraded: Upgraded,
addr: String,
socks_addr: SocketAddr,
auth: &Option<Auth>,
auth: Option<&Auth>,
) -> Result<()> {
let mut stream = match auth {
Some(auth) => {
@ -147,8 +147,8 @@ async fn tunnel(
pub async fn proxy_request(
stream: TcpStream,
socks_addr: SocketAddr,
auth_details: &'static Option<Auth>,
allowed_domains: &'static Option<Vec<String>>,
auth_details: Option<&'static Auth>,
allowed_domains: Option<&'static Vec<String>>,
) -> color_eyre::Result<()> {
let io = TokioIo::new(stream);

2
tests/proxy.rs

@ -35,7 +35,7 @@ async fn simple_test() -> Result<()> {
let addr = listener.local_addr()?;
let _ = tokio::task::spawn(async move {
let (stream, proxy_addr) = listener.accept().await?;
proxy_request(stream, socks_proxy_addr, &None, &None).await?;
proxy_request(stream, socks_proxy_addr, None, None).await?;
eprintln!("new connection from: {:?}", proxy_addr);
Ok::<_, color_eyre::eyre::Error>(())
});

Loading…
Cancel
Save