Skip to content

Commit

Permalink
pr: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Dec 15, 2022
1 parent b0076e8 commit f50d262
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions iroh-gateway/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions iroh-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}

Expand All @@ -69,7 +65,7 @@ impl Config {
indexer_endpoint: None,
metrics: MetricsConfig::default(),
use_denylist: false,
redirect_to_subdomain: true,
redirect_to_subdomain: false,
}
}

Expand Down
2 changes: 0 additions & 2 deletions iroh-gateway/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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
}

Expand Down
18 changes: 9 additions & 9 deletions iroh-gateway/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::{
};

enum RequestPreprocessingResult {
ResponseImmediately(GatewayResponse),
RespondImmediately(GatewayResponse),
ShouldRequestData(Box<IpfsRequest>),
}

Expand Down Expand Up @@ -135,7 +135,7 @@ async fn request_preprocessing<T: ContentLoader + Unpin>(
query_params: &GetParams,
request_headers: &HeaderMap,
response_headers: &mut HeaderMap,
is_subdomain_mode: bool,
subdomain_mode: bool,
) -> Result<RequestPreprocessingResult, GatewayError> {
if path.typ().as_str() != SCHEME_IPFS && path.typ().as_str() != SCHEME_IPNS {
return Err(GatewayError::new(
Expand All @@ -148,7 +148,7 @@ async fn request_preprocessing<T: ContentLoader + Unpin>(
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)?;
Expand All @@ -166,7 +166,7 @@ async fn request_preprocessing<T: ContentLoader + Unpin>(
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()),
));
}
Expand All @@ -176,7 +176,7 @@ async fn request_preprocessing<T: ContentLoader + Unpin>(
.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
Expand Down Expand Up @@ -205,7 +205,7 @@ async fn request_preprocessing<T: ContentLoader + Unpin>(
.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)))
}
Expand All @@ -217,7 +217,7 @@ pub async fn handler<T: ContentLoader + Unpin>(
query_params: &GetParams,
request_headers: &HeaderMap,
http_req: HttpRequest<Body>,
is_subdomain_mode: bool,
subdomain_mode: bool,
) -> Result<GatewayResponse, GatewayError> {
let start_time = time::Instant::now();
let mut response_headers = HeaderMap::new();
Expand All @@ -227,11 +227,11 @@ pub async fn handler<T: ContentLoader + Unpin>(
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
Expand Down

0 comments on commit f50d262

Please sign in to comment.