Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc

Issue 2224003004: Add Accept-Encoding: br for secure data reduction proxy requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add Accept-Encoding: br for secure data reduction proxy requests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
index 7f0382e235b503e74ba94d764af4f086d069b65b..057ac1cd51d46d848d35345266581c6dab064632 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
@@ -23,8 +23,10 @@
#include "crypto/random.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_flags.h"
+#include "net/http/http_request_headers.h"
#include "net/proxy/proxy_server.h"
#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_context.h"
#if defined(USE_GOOGLE_API_KEYS_FOR_AUTH_KEY)
#include "google_apis/google_api_keys.h"
@@ -37,6 +39,17 @@ std::string FormatOption(const std::string& name, const std::string& value) {
return name + "=" + value;
}
+bool HasBrotliAcceptEncoding(base::StringPiece accept_encoding_header) {
+ for (base::StringPiece encoding : base::SplitStringPiece(
+ accept_encoding_header, ",", base::TRIM_WHITESPACE,
+ base::SPLIT_WANT_NONEMPTY)) {
+ if (encoding == "br") {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace
const char kSessionHeaderOption[] = "ps";
@@ -154,6 +167,24 @@ void DataReductionProxyRequestOptions::AddRequestHeader(
request_headers->SetHeader(kChromeProxyHeader, header_value);
}
+void DataReductionProxyRequestOptions::AddBrotliAcceptEncoding(
+ const net::URLRequest& request,
+ net::HttpRequestHeaders* request_headers) {
+ std::string accept_encoding_header;
+ if (!request.context()->enable_brotli() ||
+ !request_headers->GetHeader(net::HttpRequestHeaders::kAcceptEncoding,
+ &accept_encoding_header) ||
+ HasBrotliAcceptEncoding(accept_encoding_header))
+ return;
+ if (accept_encoding_header.empty()) {
+ accept_encoding_header = "br";
+ } else {
+ accept_encoding_header += ", br";
+ }
+ request_headers->SetHeader(net::HttpRequestHeaders::kAcceptEncoding,
+ accept_encoding_header);
+}
+
void DataReductionProxyRequestOptions::ComputeCredentials(
const base::Time& now,
std::string* session,

Powered by Google App Engine
This is Rietveld 408576698