Browse Source

Send proper Host header in federation requests

merge-requests/44/head
Gabriel Souza Franco 5 years ago
parent
commit
17a4cb2fd0
  1. 2
      src/database/globals.rs
  2. 18
      src/server_server.rs

2
src/database/globals.rs

@ -9,7 +9,7 @@ use trust_dns_resolver::TokioAsyncResolver;
pub const COUNTER: &str = "c"; pub const COUNTER: &str = "c";
type WellKnownMap = HashMap<Box<ServerName>, (String, Option<String>)>; type WellKnownMap = HashMap<Box<ServerName>, (String, 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

18
src/server_server.rs

@ -135,11 +135,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");
@ -227,10 +225,10 @@ 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) => {
@ -245,6 +243,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 => {
@ -266,10 +265,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…
Cancel
Save