Skip to content

Commit

Permalink
correct interaction with previously overridden headers
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Apr 8, 2021
1 parent 0c28a25 commit 86154a9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions browser/net/brave_ad_block_tp_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,25 @@ int OnHeadersReceived_AdBlockCspWork(

if (ctx->resource_type == blink::mojom::ResourceType::kMainFrame ||
ctx->resource_type == blink::mojom::ResourceType::kSubFrame) {
// If the override_response_headers have already been populated, we should
// use those directly. Otherwise, we populate them from the original
// headers.
if (!*override_response_headers) {
*override_response_headers =
new net::HttpResponseHeaders(response_headers->raw_headers());
}

scoped_refptr<base::SequencedTaskRunner> task_runner =
g_brave_browser_process->ad_block_service()->GetTaskRunner();

std::string original_csp_string;
base::Optional<std::string> original_csp = base::nullopt;
if (response_headers->GetNormalizedHeader("Content-Security-Policy",
&original_csp_string)) {
if ((*override_response_headers)
->GetNormalizedHeader("Content-Security-Policy",
&original_csp_string)) {
original_csp = base::Optional<std::string>(original_csp_string);
}

*override_response_headers =
new net::HttpResponseHeaders(response_headers->raw_headers());
(*override_response_headers)->RemoveHeader("Content-Security-Policy");

task_runner->PostTaskAndReplyWithResult(
Expand Down

0 comments on commit 86154a9

Please sign in to comment.