Add default content type
This commit is contained in:
parent
27df033448
commit
365ddd7875
2 changed files with 9 additions and 3 deletions
|
@ -16,7 +16,7 @@ use std::time::Duration;
|
||||||
use super::{tunnel_to_jwt_token, JwtTunnelConfig, RemoteAddr, JWT_DECODE, JWT_HEADER_PREFIX};
|
use super::{tunnel_to_jwt_token, JwtTunnelConfig, RemoteAddr, JWT_DECODE, JWT_HEADER_PREFIX};
|
||||||
use crate::{socks5, tcp, tls, udp, LocalProtocol, TlsServerConfig, WsServerConfig};
|
use crate::{socks5, tcp, tls, udp, LocalProtocol, TlsServerConfig, WsServerConfig};
|
||||||
use hyper::body::{Frame, Incoming};
|
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::http::HeaderValue;
|
||||||
use hyper::server::conn::{http1, http2};
|
use hyper::server::conn::{http1, http2};
|
||||||
use hyper::service::service_fn;
|
use hyper::service::service_fn;
|
||||||
|
@ -447,7 +447,7 @@ async fn ws_server_upgrade(
|
||||||
async fn http_server_upgrade(
|
async fn http_server_upgrade(
|
||||||
server_config: Arc<WsServerConfig>,
|
server_config: Arc<WsServerConfig>,
|
||||||
mut client_addr: SocketAddr,
|
mut client_addr: SocketAddr,
|
||||||
req: Request<Incoming>,
|
mut req: Request<Incoming>,
|
||||||
) -> Response<Either<String, BoxBody<Bytes, anyhow::Error>>> {
|
) -> Response<Either<String, BoxBody<Bytes, anyhow::Error>>> {
|
||||||
match extract_x_forwarded_for(&req) {
|
match extract_x_forwarded_for(&req) {
|
||||||
Ok(Some((x_forward_for, x_forward_for_str))) => {
|
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;
|
let (remote_addr, local_rx, local_tx) = tunnel;
|
||||||
info!("connected to {:?} {}:{}", req_protocol, remote_addr.host, remote_addr.port);
|
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_rx = BodyStream::new(req.into_body());
|
||||||
let (ws_tx, rx) = mpsc::channel::<Bytes>(1024);
|
let (ws_tx, rx) = mpsc::channel::<Bytes>(1024);
|
||||||
let body = BoxBody::new(StreamBody::new(
|
let body = BoxBody::new(StreamBody::new(
|
||||||
|
@ -527,6 +528,10 @@ async fn http_server_upgrade(
|
||||||
response.headers_mut().insert(COOKIE, header_val);
|
response.headers_mut().insert(COOKIE, header_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(content_type) = req_content_type {
|
||||||
|
response.headers_mut().insert(CONTENT_TYPE, content_type);
|
||||||
|
}
|
||||||
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use anyhow::{anyhow, Context};
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use http_body_util::{BodyExt, BodyStream, StreamBody};
|
use http_body_util::{BodyExt, BodyStream, StreamBody};
|
||||||
use hyper::body::{Frame, Incoming};
|
use hyper::body::{Frame, Incoming};
|
||||||
use hyper::header::{AUTHORIZATION, COOKIE};
|
use hyper::header::{AUTHORIZATION, CONTENT_TYPE, COOKIE};
|
||||||
use hyper::http::response::Parts;
|
use hyper::http::response::Parts;
|
||||||
use hyper::Request;
|
use hyper::Request;
|
||||||
use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer};
|
use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer};
|
||||||
|
@ -116,6 +116,7 @@ pub async fn connect(
|
||||||
&client_cfg.http_upgrade_path_prefix
|
&client_cfg.http_upgrade_path_prefix
|
||||||
))
|
))
|
||||||
.header(COOKIE, tunnel_to_jwt_token(request_id, dest_addr))
|
.header(COOKIE, tunnel_to_jwt_token(request_id, dest_addr))
|
||||||
|
.header(CONTENT_TYPE, "application/grpc+proto")
|
||||||
.version(hyper::Version::HTTP_2);
|
.version(hyper::Version::HTTP_2);
|
||||||
|
|
||||||
for (k, v) in &client_cfg.http_headers {
|
for (k, v) in &client_cfg.http_headers {
|
||||||
|
|
Loading…
Reference in a new issue