Skip to content

Commit

Permalink
support subdomain & path gateways for fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Oct 24, 2022
1 parent 21976ab commit 23d3a0d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion iroh-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct Config {
/// flag to toggle whether the gateway should use denylist on requests
pub use_denylist: bool,
/// URL of gateways to be used by the racing resolver.
/// strings can either be urls or subdomain gateway roots
/// values without https:// prefix are treated as subdomain gateways (eg: dweb.link)
/// values with are treated as IPFS path gateways (eg: https://ipfs.io)
pub http_resolvers: Option<Vec<String>>,
/// rpc addresses for the gateway & addresses for the rpc client to dial
pub rpc_client: RpcClientConfig,
Expand Down Expand Up @@ -208,7 +211,10 @@ mod tests {
Value::new(None, default.public_url_base.clone()),
);
expect.insert("port".to_string(), Value::new(None, default.port as i64));
expect.insert("denylist".to_string(), Value::new(None, default.denylist));
expect.insert(
"use_denylist".to_string(),
Value::new(None, default.denylist),
);
expect.insert(
"headers".to_string(),
Value::new(None, collect_headers(&default.headers).unwrap()),
Expand Down
6 changes: 4 additions & 2 deletions iroh-resolver/src/racing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ impl RacingLoader {
async fn fetch_http(&self, cid: &Cid) -> Result<(Bytes, String), anyhow::Error> {
let gateway = self.try_raw_gateway()?;
let cid_str = multibase::encode(multibase::Base::Base32Lower, cid.to_bytes().as_slice());
// let gateway_url = format!("https://{}.ipfs.{}?format=raw", cid_str, gateway);
let gateway_url = format!("{}/ipfs/{}?format=raw", gateway, cid_str);
let mut gateway_url = format!("https://{}.ipfs.{}?format=raw", cid_str, gateway);
if gateway.starts_with("https://") || gateway.starts_with("http://") {
gateway_url = format!("{}/ipfs/{}?format=raw", gateway, cid_str);
}

This comment has been minimized.

Copy link
@fabricedesre

fabricedesre Oct 24, 2022

Contributor

more idiomatic:

let gateway_url = if gateway.starts_with("https://") || gateway.starts_with("http://") {
    format!("{}/ipfs/{}?format=raw", gateway, cid_str)
} else {
    format!("https://{}.ipfs.{}?format=raw", cid_str, gateway);
};

Also, not a big fan of accepting http:// with hosts that are not localhost.

debug!("Will fetch {}", gateway_url);
let response = reqwest::get(gateway_url).await?;
response
Expand Down

0 comments on commit 23d3a0d

Please sign in to comment.