diff --git a/browser/net/ipfs_redirect_network_delegate_helper.cc b/browser/net/ipfs_redirect_network_delegate_helper.cc index 5072f4245128..420eb61a5288 100644 --- a/browser/net/ipfs_redirect_network_delegate_helper.cc +++ b/browser/net/ipfs_redirect_network_delegate_helper.cc @@ -8,6 +8,7 @@ #include #include "brave/components/ipfs/ipfs_utils.h" +#include "chrome/common/channel_info.h" #include "components/prefs/pref_service.h" #include "components/user_prefs/user_prefs.h" #include "content/public/browser/browser_context.h" @@ -61,7 +62,8 @@ int OnHeadersReceived_IPFSRedirectWork( } std::string ipfs_path; - if (ctx->ipfs_auto_fallback && response_headers && + bool api_gateway = IsAPIGateway(ctx->request_url, chrome::GetChannel()); + if (ctx->ipfs_auto_fallback && !api_gateway && response_headers && response_headers->GetNormalizedHeader("x-ipfs-path", &ipfs_path) && // Make sure we don't infinite redirect !ctx->request_url.DomainIs(ctx->ipfs_gateway_url.host())) { diff --git a/browser/net/ipfs_redirect_network_delegate_helper_unittest.cc b/browser/net/ipfs_redirect_network_delegate_helper_unittest.cc index c8097aa4f405..b4ac62b2ce29 100644 --- a/browser/net/ipfs_redirect_network_delegate_helper_unittest.cc +++ b/browser/net/ipfs_redirect_network_delegate_helper_unittest.cc @@ -193,6 +193,15 @@ TEST_F(IPFSRedirectNetworkDelegateHelperTest, HeadersIPFSWorkNoRedirect) { EXPECT_FALSE(overwrite_response_headers->EnumerateHeader(nullptr, "Location", &location)); EXPECT_TRUE(allowed_unsafe_redirect_url.is_empty()); + + request_info->request_url = GetAPIServer(chrome::GetChannel()); + request_info->ipfs_auto_fallback = true; + + rc = ipfs::OnHeadersReceived_IPFSRedirectWork( + orig_response_headers.get(), &overwrite_response_headers, + &allowed_unsafe_redirect_url, brave::ResponseCallback(), request_info); + EXPECT_EQ(rc, net::OK); + EXPECT_TRUE(allowed_unsafe_redirect_url.is_empty()); } } // namespace ipfs