diff --git a/src/tunnel/server.rs b/src/tunnel/server.rs index a684249..109a545 100644 --- a/src/tunnel/server.rs +++ b/src/tunnel/server.rs @@ -16,7 +16,7 @@ use std::time::Duration; use super::{tunnel_to_jwt_token, JwtTunnelConfig, RemoteAddr, JWT_DECODE, JWT_HEADER_PREFIX}; use crate::{socks5, tcp, tls, udp, LocalProtocol, TlsServerConfig, WsServerConfig}; use hyper::body::{Frame, Incoming}; -use hyper::header::{COOKIE, SEC_WEBSOCKET_PROTOCOL}; +use hyper::header::{CONTENT_TYPE, COOKIE, SEC_WEBSOCKET_PROTOCOL}; use hyper::http::HeaderValue; use hyper::server::conn::{http1, http2}; use hyper::service::service_fn; @@ -447,7 +447,7 @@ async fn ws_server_upgrade( async fn http_server_upgrade( server_config: Arc, mut client_addr: SocketAddr, - req: Request, + mut req: Request, ) -> Response>> { match extract_x_forwarded_for(&req) { Ok(Some((x_forward_for, x_forward_for_str))) => { @@ -490,6 +490,7 @@ async fn http_server_upgrade( let (remote_addr, local_rx, local_tx) = tunnel; info!("connected to {:?} {}:{}", req_protocol, remote_addr.host, remote_addr.port); + let req_content_type = req.headers_mut().remove(CONTENT_TYPE); let ws_rx = BodyStream::new(req.into_body()); let (ws_tx, rx) = mpsc::channel::(1024); let body = BoxBody::new(StreamBody::new( @@ -527,6 +528,10 @@ async fn http_server_upgrade( response.headers_mut().insert(COOKIE, header_val); } + if let Some(content_type) = req_content_type { + response.headers_mut().insert(CONTENT_TYPE, content_type); + } + response } diff --git a/src/tunnel/transport/http2.rs b/src/tunnel/transport/http2.rs index 95399f5..dd9a713 100644 --- a/src/tunnel/transport/http2.rs +++ b/src/tunnel/transport/http2.rs @@ -5,7 +5,7 @@ use anyhow::{anyhow, Context}; use bytes::{Bytes, BytesMut}; use http_body_util::{BodyExt, BodyStream, StreamBody}; use hyper::body::{Frame, Incoming}; -use hyper::header::{AUTHORIZATION, COOKIE}; +use hyper::header::{AUTHORIZATION, CONTENT_TYPE, COOKIE}; use hyper::http::response::Parts; use hyper::Request; use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer}; @@ -116,6 +116,7 @@ pub async fn connect( &client_cfg.http_upgrade_path_prefix )) .header(COOKIE, tunnel_to_jwt_token(request_id, dest_addr)) + .header(CONTENT_TYPE, "application/grpc+proto") .version(hyper::Version::HTTP_2); for (k, v) in &client_cfg.http_headers {