-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6582 from brave/ipfs-content
Resolve subresources for IPFS and IPNS too
- Loading branch information
Showing
20 changed files
with
270 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/net/ipfs_redirect_network_delegate_helper.h" | ||
|
||
#include "brave/components/ipfs/browser/translate_ipfs_uri.h" | ||
|
||
namespace ipfs { | ||
|
||
int OnBeforeURLRequest_IPFSRedirectWork( | ||
const brave::ResponseCallback& next_callback, | ||
std::shared_ptr<brave::BraveRequestInfo> ctx) { | ||
GURL new_url; | ||
if (ipfs::TranslateIPFSURI(ctx->request_url, &new_url, ctx->ipfs_local)) { | ||
ctx->new_url_spec = new_url.spec(); | ||
} | ||
return net::OK; | ||
} | ||
|
||
} // namespace ipfs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_NET_IPFS_REDIRECT_NETWORK_DELEGATE_HELPER_H_ | ||
#define BRAVE_BROWSER_NET_IPFS_REDIRECT_NETWORK_DELEGATE_HELPER_H_ | ||
|
||
#include <memory> | ||
#include "brave/browser/net/url_context.h" | ||
|
||
namespace ipfs { | ||
|
||
int OnBeforeURLRequest_IPFSRedirectWork( | ||
const brave::ResponseCallback& next_callback, | ||
std::shared_ptr<brave::BraveRequestInfo> ctx); | ||
|
||
} // namespace ipfs | ||
|
||
#endif // BRAVE_BROWSER_NET_IPFS_REDIRECT_NETWORK_DELEGATE_HELPER_H_ |
76 changes: 76 additions & 0 deletions
76
browser/net/ipfs_redirect_network_delegate_helper_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/net/ipfs_redirect_network_delegate_helper.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "brave/browser/net/url_context.h" | ||
#include "brave/common/translate_network_constants.h" | ||
#include "chrome/test/base/chrome_render_view_host_test_harness.h" | ||
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | ||
#include "net/url_request/url_request_test_util.h" | ||
#include "url/gurl.h" | ||
|
||
namespace { | ||
|
||
TEST(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIHTTPScheme) { | ||
GURL url("http://a.com/ipfs/QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG"); | ||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url); | ||
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(brave::ResponseCallback(), | ||
brave_request_info); | ||
EXPECT_EQ(rc, net::OK); | ||
EXPECT_TRUE(brave_request_info->new_url_spec.empty()); | ||
} | ||
|
||
TEST(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPFSSchemeLocal) { | ||
GURL url("ipfs://QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG"); | ||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url); | ||
brave_request_info->ipfs_local = true; | ||
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(brave::ResponseCallback(), | ||
brave_request_info); | ||
EXPECT_EQ(rc, net::OK); | ||
EXPECT_EQ(brave_request_info->new_url_spec, | ||
"http://127.0.0.1:8080/ipfs/" | ||
"QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG"); | ||
} | ||
|
||
TEST(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPFSScheme) { | ||
GURL url("ipfs://QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG"); | ||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url); | ||
brave_request_info->ipfs_local = false; | ||
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(brave::ResponseCallback(), | ||
brave_request_info); | ||
EXPECT_EQ(rc, net::OK); | ||
EXPECT_EQ(brave_request_info->new_url_spec, | ||
"https://dweb.link/ipfs/QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG"); | ||
} | ||
|
||
TEST(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPNSSchemeLocal) { | ||
GURL url("ipns://QmSrPmbaUKA3ZodhzPWZnpFgcPMFWF4QsxXbkWfEptTBJd"); | ||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url); | ||
brave_request_info->ipfs_local = true; | ||
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(brave::ResponseCallback(), | ||
brave_request_info); | ||
EXPECT_EQ(rc, net::OK); | ||
EXPECT_EQ(brave_request_info->new_url_spec, | ||
"http://127.0.0.1:8080/ipns/" | ||
"QmSrPmbaUKA3ZodhzPWZnpFgcPMFWF4QsxXbkWfEptTBJd"); | ||
} | ||
|
||
TEST(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPNSScheme) { | ||
GURL url("ipns://QmSrPmbaUKA3ZodhzPWZnpFgcPMFWF4QsxXbkWfEptTBJd"); | ||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url); | ||
brave_request_info->ipfs_local = false; | ||
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(brave::ResponseCallback(), | ||
brave_request_info); | ||
EXPECT_EQ(rc, net::OK); | ||
EXPECT_EQ(brave_request_info->new_url_spec, | ||
"https://dweb.link/ipns/QmSrPmbaUKA3ZodhzPWZnpFgcPMFWF4QsxXbkWfEptTBJd"); | ||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.