mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 16:14:11 +00:00
Refactor some code
This commit is contained in:
+3
-12
@@ -679,10 +679,7 @@ impl ConfigType {
|
||||
|
||||
/// Check if it is manager server type
|
||||
pub fn is_manager(self) -> bool {
|
||||
match self {
|
||||
ConfigType::Manager => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, ConfigType::Manager)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -696,17 +693,11 @@ pub enum Mode {
|
||||
|
||||
impl Mode {
|
||||
pub fn enable_udp(self) -> bool {
|
||||
match self {
|
||||
Mode::UdpOnly | Mode::TcpAndUdp => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Mode::UdpOnly | Mode::TcpAndUdp)
|
||||
}
|
||||
|
||||
pub fn enable_tcp(self) -> bool {
|
||||
match self {
|
||||
Mode::TcpOnly | Mode::TcpAndUdp => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Mode::TcpOnly | Mode::TcpAndUdp)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -119,10 +119,8 @@ impl<'a> AsMut<[u8]> for SealBuffer<'a> {
|
||||
|
||||
impl<'a, 'in_out> Extend<&'in_out u8> for SealBuffer<'a> {
|
||||
fn extend<T: IntoIterator<Item = &'in_out u8>>(&mut self, iter: T) {
|
||||
let mut idx = 0;
|
||||
for b in iter {
|
||||
for (idx, b) in iter.into_iter().enumerate() {
|
||||
self.buffer[self.input_len + idx] = *b;
|
||||
idx += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,11 +391,8 @@ fn host_addr(uri: &Uri) -> Option<Address> {
|
||||
}
|
||||
|
||||
fn check_keep_alive(version: Version, headers: &HeaderMap<HeaderValue>, check_proxy: bool) -> bool {
|
||||
let mut conn_keep_alive = match version {
|
||||
Version::HTTP_09 | Version::HTTP_10 => false,
|
||||
// HTTP/1.1, HTTP/2, HTTP/3 keeps alive by default
|
||||
_ => true,
|
||||
};
|
||||
// HTTP/1.1, HTTP/2, HTTP/3 keeps alive by default
|
||||
let mut conn_keep_alive = !matches!(version, Version::HTTP_09 | Version::HTTP_10);
|
||||
|
||||
if check_proxy {
|
||||
// Modern browers will send Proxy-Connection instead of Connection
|
||||
|
||||
@@ -180,10 +180,7 @@ enum ProxyConnection {
|
||||
impl ProxyConnection {
|
||||
/// Check if the underlying connection is proxied
|
||||
fn is_proxied(&self) -> bool {
|
||||
match *self {
|
||||
ProxyConnection::Proxied { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, ProxyConnection::Proxied { .. })
|
||||
}
|
||||
|
||||
fn local_addr(&self) -> io::Result<SocketAddr> {
|
||||
|
||||
Reference in New Issue
Block a user