Skip to content

Commit

Permalink
Merge pull request #9031 from brave/issue-16112
Browse files Browse the repository at this point in the history
Do not fallback api urls
  • Loading branch information
spylogsster authored Jun 9, 2021
2 parents 4c6f795 + f624350 commit 6bd272d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion browser/net/ipfs_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>

#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"
Expand Down Expand Up @@ -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())) {
Expand Down
9 changes: 9 additions & 0 deletions browser/net/ipfs_redirect_network_delegate_helper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6bd272d

Please sign in to comment.