let hyper send the host header

This commit is contained in:
Toshit Chawda 2024-10-20 17:57:48 -07:00
parent 12cb93b018
commit 3941d2fad1
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D

View file

@ -11,7 +11,7 @@ use futures_util::TryStreamExt;
use http::{ use http::{
header::{ header::{
InvalidHeaderName, InvalidHeaderValue, ACCEPT_ENCODING, CONNECTION, CONTENT_LENGTH, InvalidHeaderName, InvalidHeaderValue, ACCEPT_ENCODING, CONNECTION, CONTENT_LENGTH,
CONTENT_TYPE, HOST, USER_AGENT, CONTENT_TYPE, USER_AGENT,
}, },
method::InvalidMethod, method::InvalidMethod,
uri::{InvalidUri, InvalidUriParts}, uri::{InvalidUri, InvalidUriParts},
@ -523,13 +523,8 @@ impl EpoxyClient {
&& let Some(mut new_req) = new_req && let Some(mut new_req) = new_req
&& let Some(location) = res.headers().get("Location") && let Some(location) = res.headers().get("Location")
&& let Ok(redirect_url) = new_req.uri().get_redirect(location) && let Ok(redirect_url) = new_req.uri().get_redirect(location)
&& let Some(redirect_url_authority) = redirect_url.clone().authority()
{ {
*new_req.uri_mut() = redirect_url; *new_req.uri_mut() = redirect_url;
new_req.headers_mut().insert(
"Host",
HeaderValue::from_str(redirect_url_authority.as_str())?,
);
Ok(EpoxyResponse::Redirect((res, new_req))) Ok(EpoxyResponse::Redirect((res, new_req)))
} else { } else {
Ok(EpoxyResponse::Success(res)) Ok(EpoxyResponse::Success(res))
@ -575,12 +570,6 @@ impl EpoxyClient {
url.scheme_str().map(ToString::to_string), url.scheme_str().map(ToString::to_string),
))?; ))?;
let host = url.host().ok_or(EpoxyError::NoUrlHost)?;
let port_str = url
.port_u16()
.map(|x| format!(":{}", x))
.unwrap_or_default();
let request_method = object_get(&options, "method") let request_method = object_get(&options, "method")
.as_string() .as_string()
.unwrap_or_else(|| "GET".to_string()); .unwrap_or_else(|| "GET".to_string());
@ -635,10 +624,6 @@ impl EpoxyClient {
} }
headers_map.insert(CONNECTION, HeaderValue::from_static("keep-alive")); headers_map.insert(CONNECTION, HeaderValue::from_static("keep-alive"));
headers_map.insert(USER_AGENT, HeaderValue::from_str(&self.user_agent)?); headers_map.insert(USER_AGENT, HeaderValue::from_str(&self.user_agent)?);
headers_map.insert(
HOST,
HeaderValue::from_str(&format!("{}{}", host, port_str))?,
);
if let Some(content_type) = body_content_type { if let Some(content_type) = body_content_type {
headers_map.insert(CONTENT_TYPE, HeaderValue::from_str(&content_type)?); headers_map.insert(CONTENT_TYPE, HeaderValue::from_str(&content_type)?);