From bda227b455e54d46aacab1e2ff41ad49a8613cbc Mon Sep 17 00:00:00 2001 From: arloor Date: Wed, 4 Sep 2024 17:05:13 +0800 Subject: [PATCH] chore: remove commented out code in launch.json and http_client.rs --- .vscode/launch.json | 4 ++-- .../src/local/http/http_client.rs | 20 +++++++++++-------- .../src/local/net/tcp/auto_proxy_stream.rs | 7 +++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 80f01618b1ae..b4b5be8ccf2b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,8 +19,8 @@ "aes-256-gcm", "-s", "us.arloor.dev:444", - "--protocol", - "http", + // "--protocol", + // "http", "--use-http-tunnel=true" ], "cwd": "${workspaceFolder}", diff --git a/crates/shadowsocks-service/src/local/http/http_client.rs b/crates/shadowsocks-service/src/local/http/http_client.rs index 214cf08a769a..994901bdc318 100644 --- a/crates/shadowsocks-service/src/local/http/http_client.rs +++ b/crates/shadowsocks-service/src/local/http/http_client.rs @@ -24,7 +24,11 @@ use pin_project::pin_project; use shadowsocks::relay::Address; use tokio::sync::Mutex; -use crate::local::{context::ServiceContext, loadbalancing::PingBalancer, net::AutoProxyClientStream}; +use crate::local::{ + context::ServiceContext, + loadbalancing::PingBalancer, + net::{tcp::auto_proxy_stream::BasicAuth, AutoProxyClientStream}, +}; use super::{ http_stream::ProxyHttpStream, @@ -195,7 +199,7 @@ where &self, host: Address, mut c: HttpConnection, - mut req: Request, + req: Request, ) -> hyper::Result> { trace!("HTTP making request to host: {}, request: {:?}", host, req); let response = c.send_request(req).await?; @@ -221,8 +225,8 @@ where } enum HttpConnection { - Http1(http1::SendRequest, Option), - Http2(http2::SendRequest, Option), + Http1(http1::SendRequest, Option), + Http2(http2::SendRequest, Option), } impl HttpConnection @@ -343,14 +347,14 @@ where pub async fn send_request(&mut self, mut req: Request) -> hyper::Result> { match self { HttpConnection::Http1(r, auth) => { - if let Some(auth) = auth { - req.headers_mut().insert("Proxy-Authorization", auth.parse().unwrap()); + if let Some(auth) = &auth { + req.headers_mut().insert("Proxy-Authorization", auth.0.parse().unwrap()); } r.send_request(req).await } HttpConnection::Http2(r, auth) => { - if let Some(auth) = auth { - req.headers_mut().insert("Proxy-Authorization", auth.parse().unwrap()); + if let Some(auth) = &auth { + req.headers_mut().insert("Proxy-Authorization", auth.0.parse().unwrap()); } r.send_request(req).await } diff --git a/crates/shadowsocks-service/src/local/net/tcp/auto_proxy_stream.rs b/crates/shadowsocks-service/src/local/net/tcp/auto_proxy_stream.rs index 6ea5160ac315..d26d444898f9 100644 --- a/crates/shadowsocks-service/src/local/net/tcp/auto_proxy_stream.rs +++ b/crates/shadowsocks-service/src/local/net/tcp/auto_proxy_stream.rs @@ -3,7 +3,6 @@ use std::{ io::{self, ErrorKind, IoSlice}, net::SocketAddr, - ops::Add, pin::{self, Pin}, sync::{Arc, LazyLock}, task::{self, Poll}, @@ -28,7 +27,7 @@ use crate::{ local::{context::ServiceContext, loadbalancing::ServerIdent}, net::MonProxyStream, }; - +pub struct BasicAuth(pub String); use super::auto_proxy_io::AutoProxyIo; /// Unified stream for bypassed and proxied connections @@ -111,10 +110,10 @@ impl AutoProxyClientStream { AutoProxyClientStream::Bypassed(_) => Ok(()), } } - pub fn auth(&self) -> Option { + pub fn auth(&self) -> Option { match self { AutoProxyClientStream::Proxied(_) => None, - AutoProxyClientStream::HttpTunnel(tunnel_stream) => Some(tunnel_stream.auth.clone()), + AutoProxyClientStream::HttpTunnel(tunnel_stream) => Some(BasicAuth(tunnel_stream.auth.clone())), AutoProxyClientStream::Bypassed(_) => None, } }