Refactor some code

This commit is contained in:
Stzx
2020-08-03 23:46:50 +08:00
committed by ty
parent 357e1a06f5
commit f6565fb948
4 changed files with 7 additions and 24 deletions
+3 -12
View File
@@ -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
View File
@@ -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;
}
}
}
+2 -5
View File
@@ -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
+1 -4
View File
@@ -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> {