Skip to content

Commit

Permalink
Preserve query strings on IPFS redirect
Browse files Browse the repository at this point in the history
+Adds test to make sure query string is preserved
  • Loading branch information
DAlperin authored and iefremov committed Jan 12, 2022
1 parent 544ded0 commit 02f0139
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions browser/ipfs/test/ipfs_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,21 @@ IN_PROC_BROWSER_TEST_F(IpfsServiceBrowserTest, TopLevelAutoRedirectsOn) {
EXPECT_EQ(contents->GetURL().host(), gateway.host());
}

IN_PROC_BROWSER_TEST_F(IpfsServiceBrowserTest,
TopLevelAutoRedirectsOnWithQuery) {
ResetTestServer(
base::BindRepeating(&IpfsServiceBrowserTest::HandleEmbeddedSrvrRequest,
base::Unretained(this)));
browser()->profile()->GetPrefs()->SetBoolean(kIPFSAutoRedirectGateway, true);
GURL gateway = GetURL("b.com", "/");
SetIPFSDefaultGatewayForTest(gateway);
ASSERT_TRUE(ui_test_utils::NavigateToURL(
browser(), GetURL("a.com", "/simple.html?abc=123xyz&other=qwerty")));
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(contents->GetURL().query(), "abc=123xyz&other=qwerty");
}

IN_PROC_BROWSER_TEST_F(IpfsServiceBrowserTest, TopLevelAutoRedirectsOff) {
ResetTestServer(
base::BindRepeating(&IpfsServiceBrowserTest::HandleEmbeddedSrvrRequest,
Expand Down
5 changes: 5 additions & 0 deletions browser/net/ipfs_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ int OnHeadersReceived_IPFSRedirectWork(
!ctx->request_url.DomainIs(ctx->ipfs_gateway_url.host())) {
GURL::Replacements replacements;
replacements.SetPathStr(ipfs_path);

if (ctx->request_url.has_query()) {
replacements.SetQueryStr(ctx->request_url.query_piece());
}

GURL new_url = ctx->ipfs_gateway_url.ReplaceComponents(replacements);

*override_response_headers =
Expand Down

0 comments on commit 02f0139

Please sign in to comment.