lint
This commit is contained in:
parent
677b29bedf
commit
2dd99130fa
14 changed files with 140 additions and 161 deletions
|
@ -24,7 +24,7 @@ pub struct Http2TunnelRead {
|
|||
}
|
||||
|
||||
impl Http2TunnelRead {
|
||||
pub fn new(inner: BodyStream<Incoming>) -> Self {
|
||||
pub const fn new(inner: BodyStream<Incoming>) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
}
|
||||
|
@ -108,23 +108,24 @@ pub async fn connect(
|
|||
}?;
|
||||
|
||||
// In http2 HOST header does not exist, it is explicitly set in the authority from the request uri
|
||||
let (headers_file, authority) = if let Some(headers_file_path) = &client_cfg.http_headers_file {
|
||||
let (host, headers) = headers_from_file(headers_file_path);
|
||||
let host = if let Some((_, v)) = host {
|
||||
match (client_cfg.remote_addr.scheme(), client_cfg.remote_addr.port()) {
|
||||
(TransportScheme::Http, 80) | (TransportScheme::Https, 443) => {
|
||||
Some(v.to_str().unwrap_or("").to_string())
|
||||
let (headers_file, authority) = client_cfg
|
||||
.http_headers_file
|
||||
.as_ref()
|
||||
.map_or((None, None), |headers_file_path| {
|
||||
let (host, headers) = headers_from_file(headers_file_path);
|
||||
let host = if let Some((_, v)) = host {
|
||||
match (client_cfg.remote_addr.scheme(), client_cfg.remote_addr.port()) {
|
||||
(TransportScheme::Http, 80) | (TransportScheme::Https, 443) => {
|
||||
Some(v.to_str().unwrap_or("").to_string())
|
||||
}
|
||||
(_, port) => Some(format!("{}:{}", v.to_str().unwrap_or(""), port)),
|
||||
}
|
||||
(_, port) => Some(format!("{}:{}", v.to_str().unwrap_or(""), port)),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
(Some(headers), host)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
(Some(headers), host)
|
||||
});
|
||||
|
||||
let mut req = Request::builder()
|
||||
.method("POST")
|
||||
|
@ -133,7 +134,7 @@ pub async fn connect(
|
|||
client_cfg.remote_addr.scheme(),
|
||||
authority
|
||||
.as_deref()
|
||||
.unwrap_or(client_cfg.http_header_host.to_str().unwrap_or("")),
|
||||
.unwrap_or_else(|| client_cfg.http_header_host.to_str().unwrap_or("")),
|
||||
&client_cfg.http_upgrade_path_prefix
|
||||
))
|
||||
.header(COOKIE, tunnel_to_jwt_token(request_id, dest_addr))
|
||||
|
|
|
@ -24,7 +24,7 @@ pub async fn propagate_local_to_remote(
|
|||
// We do our own pin_mut! to avoid shadowing timeout and be able to reset it, on next loop iteration
|
||||
// We reuse the future to avoid creating a timer in the tight loop
|
||||
let frequency = ping_frequency.unwrap_or(Duration::from_secs(3600 * 24));
|
||||
let start_at = Instant::now().checked_add(frequency).unwrap_or(Instant::now());
|
||||
let start_at = Instant::now().checked_add(frequency).unwrap_or_else(Instant::now);
|
||||
let timeout = tokio::time::interval_at(start_at, frequency);
|
||||
let should_close = close_tx.closed().fuse();
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@ pub enum TunnelReader {
|
|||
impl TunnelRead for TunnelReader {
|
||||
async fn copy(&mut self, writer: impl AsyncWrite + Unpin + Send) -> Result<(), std::io::Error> {
|
||||
match self {
|
||||
TunnelReader::Websocket(s) => s.copy(writer).await,
|
||||
TunnelReader::Http2(s) => s.copy(writer).await,
|
||||
Self::Websocket(s) => s.copy(writer).await,
|
||||
Self::Http2(s) => s.copy(writer).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,29 +52,29 @@ pub enum TunnelWriter {
|
|||
impl TunnelWrite for TunnelWriter {
|
||||
fn buf_mut(&mut self) -> &mut BytesMut {
|
||||
match self {
|
||||
TunnelWriter::Websocket(s) => s.buf_mut(),
|
||||
TunnelWriter::Http2(s) => s.buf_mut(),
|
||||
Self::Websocket(s) => s.buf_mut(),
|
||||
Self::Http2(s) => s.buf_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn write(&mut self) -> Result<(), std::io::Error> {
|
||||
match self {
|
||||
TunnelWriter::Websocket(s) => s.write().await,
|
||||
TunnelWriter::Http2(s) => s.write().await,
|
||||
Self::Websocket(s) => s.write().await,
|
||||
Self::Http2(s) => s.write().await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn ping(&mut self) -> Result<(), std::io::Error> {
|
||||
match self {
|
||||
TunnelWriter::Websocket(s) => s.ping().await,
|
||||
TunnelWriter::Http2(s) => s.ping().await,
|
||||
Self::Websocket(s) => s.ping().await,
|
||||
Self::Http2(s) => s.ping().await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn close(&mut self) -> Result<(), std::io::Error> {
|
||||
match self {
|
||||
TunnelWriter::Websocket(s) => s.close().await,
|
||||
TunnelWriter::Http2(s) => s.close().await,
|
||||
Self::Websocket(s) => s.close().await,
|
||||
Self::Http2(s) => s.close().await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ pub struct WebsocketTunnelRead {
|
|||
}
|
||||
|
||||
impl WebsocketTunnelRead {
|
||||
pub fn new(ws: WebSocketRead<ReadHalf<TokioIo<Upgraded>>>) -> Self {
|
||||
pub const fn new(ws: WebSocketRead<ReadHalf<TokioIo<Upgraded>>>) -> Self {
|
||||
Self { inner: ws }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue