mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-05-04 20:30:33 +00:00
Use Option type for credentials
This commit applys the diff by @ssrlive from
3223ca4e22 (commitcomment-105521241)
.
This commit is contained in:
parent
8dd075a7f4
commit
2f295c3fdc
7 changed files with 40 additions and 35 deletions
|
@ -35,7 +35,7 @@ impl HttpConnection {
|
|||
server_outbuf.extend(b" HTTP/1.1\r\nHost: ".iter());
|
||||
server_outbuf.extend(connection.dst.to_string().as_bytes());
|
||||
server_outbuf.extend(b"\r\n".iter());
|
||||
if credentials.authenticate {
|
||||
if let Some(credentials) = credentials {
|
||||
server_outbuf.extend(b"Proxy-Authorization: Basic ");
|
||||
let mut auth_plain = credentials.username.clone();
|
||||
auth_plain.extend(b":".iter());
|
||||
|
@ -165,7 +165,7 @@ impl TcpProxy for HttpConnection {
|
|||
|
||||
pub struct HttpManager {
|
||||
server: std::net::SocketAddr,
|
||||
credentials: Credentials,
|
||||
credentials: Option<Credentials>,
|
||||
}
|
||||
|
||||
impl ConnectionManager for HttpManager {
|
||||
|
@ -192,13 +192,13 @@ impl ConnectionManager for HttpManager {
|
|||
self.server
|
||||
}
|
||||
|
||||
fn get_credentials(&self) -> &Credentials {
|
||||
fn get_credentials(&self) -> &Option<Credentials> {
|
||||
&self.credentials
|
||||
}
|
||||
}
|
||||
|
||||
impl HttpManager {
|
||||
pub fn new(server: SocketAddr, credentials: Credentials) -> std::rc::Rc<Self> {
|
||||
pub fn new(server: SocketAddr, credentials: Option<Credentials>) -> std::rc::Rc<Self> {
|
||||
std::rc::Rc::new(Self {
|
||||
server,
|
||||
credentials,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue