Add default content type

This commit is contained in:
Σrebe - Romain GERARD 2024-01-17 09:16:35 +01:00
parent 27df033448
commit 365ddd7875
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4
2 changed files with 9 additions and 3 deletions

View file

@ -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<WsServerConfig>,
mut client_addr: SocketAddr,
req: Request<Incoming>,
mut req: Request<Incoming>,
) -> Response<Either<String, BoxBody<Bytes, anyhow::Error>>> {
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::<Bytes>(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
}

View file

@ -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 {