Send proper Host header in federation requests
parent
5cb15551f3
commit
7b3fe88345
|
@ -13,9 +13,7 @@ use trust_dns_resolver::TokioAsyncResolver;
|
||||||
|
|
||||||
pub const COUNTER: &str = "c";
|
pub const COUNTER: &str = "c";
|
||||||
|
|
||||||
pub type DestinationCache = Arc<RwLock<HashMap<Box<ServerName>, (String, Option<String>)>>>;
|
type WellKnownMap = HashMap<Box<ServerName>, (String, String)>;
|
||||||
type WellKnownMap = HashMap<Box<ServerName>, (String, Option<String>)>;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Globals {
|
pub struct Globals {
|
||||||
pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
|
pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
|
||||||
|
|
|
@ -139,11 +139,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(host) = host {
|
|
||||||
http_request
|
http_request
|
||||||
.headers_mut()
|
.headers_mut()
|
||||||
.insert(HOST, HeaderValue::from_str(&host).unwrap());
|
.insert(HOST, HeaderValue::from_str(&host).unwrap());
|
||||||
}
|
|
||||||
|
|
||||||
let mut reqwest_request = reqwest::Request::try_from(http_request)
|
let mut reqwest_request = reqwest::Request::try_from(http_request)
|
||||||
.expect("all http requests are valid reqwest requests");
|
.expect("all http requests are valid reqwest requests");
|
||||||
|
@ -231,10 +229,9 @@ fn add_port_to_hostname(destination_str: String) -> String {
|
||||||
async fn find_actual_destination(
|
async fn find_actual_destination(
|
||||||
globals: &crate::database::globals::Globals,
|
globals: &crate::database::globals::Globals,
|
||||||
destination: &'_ ServerName,
|
destination: &'_ ServerName,
|
||||||
) -> (String, Option<String>) {
|
) -> (String, String) {
|
||||||
let mut host = None;
|
|
||||||
|
|
||||||
let destination_str = destination.as_str().to_owned();
|
let destination_str = destination.as_str().to_owned();
|
||||||
|
let mut host = destination_str.clone();
|
||||||
let actual_destination = "https://".to_owned()
|
let actual_destination = "https://".to_owned()
|
||||||
+ &match get_ip_with_port(destination_str.clone()) {
|
+ &match get_ip_with_port(destination_str.clone()) {
|
||||||
Some(host_port) => {
|
Some(host_port) => {
|
||||||
|
@ -249,6 +246,7 @@ async fn find_actual_destination(
|
||||||
match request_well_known(globals, &destination.as_str()).await {
|
match request_well_known(globals, &destination.as_str()).await {
|
||||||
// 3: A .well-known file is available
|
// 3: A .well-known file is available
|
||||||
Some(delegated_hostname) => {
|
Some(delegated_hostname) => {
|
||||||
|
host = delegated_hostname.clone();
|
||||||
match get_ip_with_port(delegated_hostname.clone()) {
|
match get_ip_with_port(delegated_hostname.clone()) {
|
||||||
Some(host_and_port) => host_and_port, // 3.1: IP literal in .well-known file
|
Some(host_and_port) => host_and_port, // 3.1: IP literal in .well-known file
|
||||||
None => {
|
None => {
|
||||||
|
@ -270,10 +268,7 @@ async fn find_actual_destination(
|
||||||
None => {
|
None => {
|
||||||
match query_srv_record(globals, &destination_str).await {
|
match query_srv_record(globals, &destination_str).await {
|
||||||
// 4: SRV record found
|
// 4: SRV record found
|
||||||
Some(hostname) => {
|
Some(hostname) => hostname,
|
||||||
host = Some(destination_str.to_owned());
|
|
||||||
hostname
|
|
||||||
}
|
|
||||||
// 5: No SRV record found
|
// 5: No SRV record found
|
||||||
None => add_port_to_hostname(destination_str.to_string()),
|
None => add_port_to_hostname(destination_str.to_string()),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue