diff --git a/iroh-gateway/src/client.rs b/iroh-gateway/src/client.rs index e9e316f19d..6c10bc7914 100644 --- a/iroh-gateway/src/client.rs +++ b/iroh-gateway/src/client.rs @@ -238,12 +238,12 @@ pub struct IpfsRequest { pub query_file_name: String, pub download: bool, pub query_params: GetParams, - pub is_subdomain_mode: bool, + pub subdomain_mode: bool, } impl IpfsRequest { pub fn request_path_for_redirection(&self) -> String { - if self.is_subdomain_mode { + if self.subdomain_mode { self.resolved_path.to_relative_string() } else { self.resolved_path.to_string() diff --git a/iroh-gateway/src/config.rs b/iroh-gateway/src/config.rs index 5785187eea..124a4af568 100644 --- a/iroh-gateway/src/config.rs +++ b/iroh-gateway/src/config.rs @@ -20,10 +20,6 @@ pub const CONFIG_FILE_NAME: &str = "gateway.config.toml"; pub const ENV_PREFIX: &str = "IROH_GATEWAY"; pub const DEFAULT_PORT: u16 = 9050; -fn set_true() -> bool { - true -} - #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct Config { /// Pretty URL to redirect to @@ -53,7 +49,7 @@ pub struct Config { #[serde(with = "http_serde::header_map")] pub headers: HeaderMap, /// Redirects to subdomains for path requests - #[serde(default = "set_true")] + #[serde(default)] pub redirect_to_subdomain: bool, } @@ -69,7 +65,7 @@ impl Config { indexer_endpoint: None, metrics: MetricsConfig::default(), use_denylist: false, - redirect_to_subdomain: true, + redirect_to_subdomain: false, } } diff --git a/iroh-gateway/src/core.rs b/iroh-gateway/src/core.rs index 12c11773ae..c887226738 100644 --- a/iroh-gateway/src/core.rs +++ b/iroh-gateway/src/core.rs @@ -345,7 +345,6 @@ mod tests { .map(|(cid, bytes)| (UnixfsNode::decode(&cid, bytes.into()).unwrap(), cid)) .unzip() .await; - // match cids and content assert_eq!(cids.len(), test_setup.file_cids.len()); assert_eq!( @@ -370,7 +369,6 @@ mod tests { for (i, node) in nodes[1..].iter().enumerate() { assert_eq!(node, &UnixfsNode::Raw(test_setup.files[i].1.clone().into())); } - test_setup.shutdown().await } diff --git a/iroh-gateway/src/handlers.rs b/iroh-gateway/src/handlers.rs index ea2efa15ff..901519b45b 100644 --- a/iroh-gateway/src/handlers.rs +++ b/iroh-gateway/src/handlers.rs @@ -54,7 +54,7 @@ use crate::{ }; enum RequestPreprocessingResult { - ResponseImmediately(GatewayResponse), + RespondImmediately(GatewayResponse), ShouldRequestData(Box), } @@ -135,7 +135,7 @@ async fn request_preprocessing( query_params: &GetParams, request_headers: &HeaderMap, response_headers: &mut HeaderMap, - is_subdomain_mode: bool, + subdomain_mode: bool, ) -> Result { if path.typ().as_str() != SCHEME_IPFS && path.typ().as_str() != SCHEME_IPNS { return Err(GatewayError::new( @@ -148,7 +148,7 @@ async fn request_preprocessing( let uri_param = query_params.uri.clone().unwrap_or_default(); if !uri_param.is_empty() { return protocol_handler_redirect(uri_param) - .map(RequestPreprocessingResult::ResponseImmediately); + .map(RequestPreprocessingResult::RespondImmediately); } service_worker_check(request_headers, &content_path)?; unsupported_header_check(request_headers)?; @@ -166,7 +166,7 @@ async fn request_preprocessing( let resolved_cid = path.root(); if handle_only_if_cached(request_headers, state, path.root()).await? { - return Ok(RequestPreprocessingResult::ResponseImmediately( + return Ok(RequestPreprocessingResult::RespondImmediately( GatewayResponse::new(StatusCode::OK, Body::empty(), HeaderMap::new()), )); } @@ -176,7 +176,7 @@ async fn request_preprocessing( .map_err(|err| GatewayError::new(StatusCode::BAD_REQUEST, &err))?; if let Some(resp) = etag_check(request_headers, resolved_cid, &format) { - return Ok(RequestPreprocessingResult::ResponseImmediately(resp)); + return Ok(RequestPreprocessingResult::RespondImmediately(resp)); } // init headers @@ -205,7 +205,7 @@ async fn request_preprocessing( .to_string(), download: query_params.download.unwrap_or_default(), query_params: query_params.clone(), - is_subdomain_mode, + subdomain_mode, }; Ok(RequestPreprocessingResult::ShouldRequestData(Box::new(req))) } @@ -217,7 +217,7 @@ pub async fn handler( query_params: &GetParams, request_headers: &HeaderMap, http_req: HttpRequest, - is_subdomain_mode: bool, + subdomain_mode: bool, ) -> Result { let start_time = time::Instant::now(); let mut response_headers = HeaderMap::new(); @@ -227,11 +227,11 @@ pub async fn handler( query_params, request_headers, &mut response_headers, - is_subdomain_mode, + subdomain_mode, ) .await? { - RequestPreprocessingResult::ResponseImmediately(gateway_response) => Ok(gateway_response), + RequestPreprocessingResult::RespondImmediately(gateway_response) => Ok(gateway_response), RequestPreprocessingResult::ShouldRequestData(req) => match method { Method::HEAD => { let path_metadata = state