Skip to content

Commit 424e850

Browse files
aeschlifelipenoris
authored andcommitted
Fix host header
1 parent e73a766 commit 424e850

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ fn create_proxied_request<B>(
225225

226226
debug!("Setting headers of proxied request");
227227

228-
request
229-
.headers_mut()
230-
.insert(HOST, HeaderValue::from_str(uri.host().unwrap())?);
228+
// remove the original HOST header. It will be set by the client that sends the request
229+
request.headers_mut().remove(HOST);
231230

232231
*request.uri_mut() = uri;
233232

tests/test_http.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use hyper::client::connect::dns::GaiResolver;
22
use hyper::client::HttpConnector;
3-
use hyper::header::{CONNECTION, UPGRADE};
3+
use hyper::header::{CONNECTION, HOST, UPGRADE};
44
use hyper::server::conn::AddrStream;
55
use hyper::service::{make_service_fn, service_fn};
6-
use hyper::{Body, Client, Request, Response, Server, StatusCode, Uri};
6+
use hyper::{Body, Client, HeaderMap, Request, Response, Server, StatusCode, Uri};
77
use hyper_reverse_proxy::ReverseProxy;
88
use std::convert::Infallible;
99
use std::net::{IpAddr, SocketAddr};
@@ -85,9 +85,15 @@ async fn test_upgrade_unrequested(ctx: &mut ProxyTestContext) {
8585
#[test_context(ProxyTestContext)]
8686
#[tokio::test]
8787
async fn test_get(ctx: &mut ProxyTestContext) {
88+
let mut headers = HeaderMap::new();
89+
headers.insert(
90+
HOST,
91+
format!("127.0.0.1:{}", ctx.http_back.port).parse().unwrap(),
92+
);
8893
ctx.http_back.add(
8994
HandlerBuilder::new("/foo")
9095
.status_code(StatusCode::OK)
96+
.headers(headers)
9197
.build(),
9298
);
9399
let resp = Client::new().get(ctx.uri("/foo")).await.unwrap();

0 commit comments

Comments
 (0)