Bump version v9.2.3

This commit is contained in:
Σrebe - Romain GERARD 2024-02-16 08:33:37 +01:00
parent 6354d8dde1
commit f4f60efd47
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4
4 changed files with 34 additions and 14 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "wstunnel" name = "wstunnel"
version = "9.2.2" version = "9.2.3"
edition = "2021" edition = "2021"
repository = "https://github.com/erebe/wstunnel.git" repository = "https://github.com/erebe/wstunnel.git"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,5 +1,5 @@
use crate::tunnel::transport::{headers_from_file, TunnelRead, TunnelWrite, MAX_PACKET_LENGTH}; use crate::tunnel::transport::{headers_from_file, TunnelRead, TunnelWrite, MAX_PACKET_LENGTH};
use crate::tunnel::{tunnel_to_jwt_token, RemoteAddr}; use crate::tunnel::{tunnel_to_jwt_token, RemoteAddr, TransportScheme};
use crate::WsClientConfig; use crate::WsClientConfig;
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
@ -7,7 +7,6 @@ use http_body_util::{BodyExt, BodyStream, StreamBody};
use hyper::body::{Frame, Incoming}; use hyper::body::{Frame, Incoming};
use hyper::header::{AUTHORIZATION, CONTENT_TYPE, COOKIE}; use hyper::header::{AUTHORIZATION, CONTENT_TYPE, COOKIE};
use hyper::http::response::Parts; use hyper::http::response::Parts;
use hyper::http::HeaderName;
use hyper::Request; use hyper::Request;
use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer}; use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer};
use log::{debug, error, warn}; use log::{debug, error, warn};
@ -110,12 +109,18 @@ pub async fn connect(
// In http2 HOST header does not exist, it is explicitly set in the authority from the request uri // 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 (headers_file, authority) = if let Some(headers_file_path) = &client_cfg.http_headers_file {
let headers = headers_from_file(headers_file_path); let (host, headers) = headers_from_file(headers_file_path);
let host = headers let host = if let Some((_, v)) = host {
.iter() match (client_cfg.remote_addr.scheme(), client_cfg.remote_addr.port()) {
.find(|(h, _)| h == HeaderName::from_static("host")) (TransportScheme::Http, 80) | (TransportScheme::Https, 443) => {
.and_then(|(_, v)| v.to_str().ok()) Some(v.to_str().unwrap_or("").to_string())
.map(|v| v.to_string()); }
(_, port) => Some(format!("{}:{}", v.to_str().unwrap_or(""), port)),
}
} else {
None
};
(Some(headers), host) (Some(headers), host)
} else { } else {
(None, None) (None, None)

View file

@ -79,24 +79,34 @@ impl TunnelWrite for TunnelWriter {
} }
} }
#[allow(clippy::type_complexity)]
#[inline] #[inline]
pub fn headers_from_file(path: &Path) -> Vec<(HeaderName, HeaderValue)> { pub fn headers_from_file(path: &Path) -> (Option<(HeaderName, HeaderValue)>, Vec<(HeaderName, HeaderValue)>) {
static HOST_HEADER: HeaderName = HeaderName::from_static("host");
let file = match std::fs::File::open(path) { let file = match std::fs::File::open(path) {
Ok(file) => file, Ok(file) => file,
Err(err) => { Err(err) => {
error!("Cannot read headers from file: {:?}: {:?}", path, err); error!("Cannot read headers from file: {:?}: {:?}", path, err);
return vec![]; return (None, vec![]);
} }
}; };
BufReader::new(file) let mut host_header = None;
let headers = BufReader::new(file)
.lines() .lines()
.filter_map(|line| { .filter_map(|line| {
let line = line.ok()?; let line = line.ok()?;
let (header, value) = line.split_once(':')?; let (header, value) = line.split_once(':')?;
let header = HeaderName::from_str(header.trim()).ok()?; let header = HeaderName::from_str(header.trim()).ok()?;
let value = HeaderValue::from_str(value.trim()).ok()?; let value = HeaderValue::from_str(value.trim()).ok()?;
if header == HOST_HEADER {
host_header = Some((header, value));
return None;
}
Some((header, value)) Some((header, value))
}) })
.collect() .collect();
(host_header, headers)
} }

View file

@ -167,10 +167,15 @@ pub async fn connect(
} }
if let Some(headers_file_path) = &client_cfg.http_headers_file { if let Some(headers_file_path) = &client_cfg.http_headers_file {
for (k, v) in headers_from_file(headers_file_path) { let (host, headers_file) = headers_from_file(headers_file_path);
for (k, v) in headers_file {
let _ = headers.remove(&k); let _ = headers.remove(&k);
headers.append(k, v); headers.append(k, v);
} }
if let Some((host, val)) = host {
let _ = headers.remove(&host);
headers.append(host, val);
}
} }
let req = req.body(Empty::<Bytes>::new()).with_context(|| { let req = req.body(Empty::<Bytes>::new()).with_context(|| {