Header override bugfix

This commit is contained in:
Fasterino
2025-10-31 06:51:23 +03:00
parent 9da8fe9889
commit 5ee87f15e7
3 changed files with 11 additions and 3 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -169,12 +169,16 @@ impl From<actix_web::HttpRequest> for HttpRequest {
.map(|x| x.to_string()) .map(|x| x.to_string())
.unwrap_or_else(|| req.uri().path().to_string()); .unwrap_or_else(|| req.uri().path().to_string());
let headers: Vec<(String, String)> = req let mut headers: Vec<(String, String)> = req
.headers() .headers()
.iter() .iter()
.map(|(k, v)| (k.to_string(), v.to_str().unwrap_or("").to_string())) .map(|(k, v)| (k.to_string(), v.to_str().unwrap_or("").to_string()))
.collect(); .collect();
if !req.headers().contains_key("Host") {
headers.push(("Host".to_owned(), req.connection_info().host().to_owned()));
}
Self { Self {
method, method,
path, path,

View File

@@ -4,6 +4,7 @@ use bytes::Bytes;
use reqwest::{ use reqwest::{
Method, Method,
header::{HeaderMap, HeaderName, HeaderValue}, header::{HeaderMap, HeaderName, HeaderValue},
redirect::Policy,
}; };
use crate::settings::Result; use crate::settings::Result;
@@ -18,14 +19,17 @@ pub struct ReqwestProxy {
impl ServerProxyService for ReqwestProxy { impl ServerProxyService for ReqwestProxy {
async fn new() -> Arc<Self> { async fn new() -> Arc<Self> {
Self { Self {
client: reqwest::Client::new(), client: reqwest::ClientBuilder::new()
.redirect(Policy::none())
.build()
.expect("Can't build client"),
} }
.into() .into()
} }
async fn fetch(&self, req: HttpRequest, connection: Connection) -> Result<HttpResponse> { async fn fetch(&self, req: HttpRequest, connection: Connection) -> Result<HttpResponse> {
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();
for (key, value) in req.headers { for (key, value) in req.headers {
headers.insert(key.parse::<HeaderName>()?, value.parse::<HeaderValue>()?); headers.append(key.parse::<HeaderName>()?, value.parse::<HeaderValue>()?);
} }
let res = self let res = self
.client .client