diff --git a/Cargo.lock b/Cargo.lock index ad1c3d1..a926352 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1563,7 +1563,7 @@ dependencies = [ [[package]] name = "primitives" version = "0.1.0" -source = "git+https://github.com/AdExNetwork/adex-validator-stack-rust?branch=bugfixes#07101f4937ef3275d2f7b20f14589d674601dd0b" +source = "git+https://github.com/AdExNetwork/adex-validator-stack-rust?branch=bugfixes#20ac5e78b6c2bc94aebe4806a256421247a3866b" dependencies = [ "async-trait", "chrono", diff --git a/src/lib.rs b/src/lib.rs index 9a4d5bd..e22b6ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ use std::net::SocketAddr; use std::sync::Arc; use thiserror::Error; -use http::{StatusCode, Uri}; +use http::{header::HOST, StatusCode, Uri}; use slog::{error, info, Logger}; pub mod cache; @@ -141,6 +141,25 @@ async fn handle( *req.uri_mut() = uri.parse::()?; + // for Cloudflare we need to add a HOST header + let market_host_header = { + let url = market.market_url.to_url(); + let host = url + .host_str() + .expect("MarketUrl always has a host") + .to_string(); + + match url.port() { + Some(port) => format!("{}:{}", host, port), + None => host, + } + }; + + let host = market_host_header + .parse() + .expect("The MarketUrl should be valid HOST header"); + req.headers_mut().insert(HOST, host); + let proxy_response = match client.request(req).await { Ok(response) => { info!(&logger, "Proxied request to market"; "uri" => uri, "method" => %method);