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

Unified Diff: net/url_request/url_request_http_job.cc

Issue 2753453003: Reject unadvertised encodings (Closed)
Patch Set: Address comments Created 3 years, 8 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: net/url_request/url_request_http_job.cc
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index b3053b24325a37a5a659adab66e0f56c65c0cc92..4db9ec146350df6f80b69e37a176eeb03afc6523 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -76,12 +76,6 @@ static const char kAvailDictionaryHeader[] = "Avail-Dictionary";
namespace {
-const char kDeflate[] = "deflate";
-const char kGZip[] = "gzip";
-const char kSdch[] = "sdch";
-const char kXGZip[] = "x-gzip";
-const char kBrotli[] = "br";
-
// True if the request method is "safe" (per section 4.2.1 of RFC 7231).
bool IsMethodSafe(const std::string& method) {
return method == "GET" || method == "HEAD" || method == "OPTIONS" ||
@@ -1064,22 +1058,31 @@ std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() {
std::vector<SourceStream::SourceType> types;
size_t iter = 0;
while (headers->EnumerateHeader(&iter, "Content-Encoding", &type)) {
- if (base::LowerCaseEqualsASCII(type, kBrotli)) {
- types.push_back(SourceStream::TYPE_BROTLI);
- } else if (base::LowerCaseEqualsASCII(type, kDeflate)) {
- types.push_back(SourceStream::TYPE_DEFLATE);
- } else if (base::LowerCaseEqualsASCII(type, kGZip) ||
- base::LowerCaseEqualsASCII(type, kXGZip)) {
- types.push_back(SourceStream::TYPE_GZIP);
- } else if (base::LowerCaseEqualsASCII(type, kSdch)) {
+ SourceStream::SourceType source_type =
+ FilterSourceStream::ParseEncodingType(type);
+ if (source_type == SourceStream::TYPE_SDCH &&
+ !request()->context()->sdch_manager()) {
// If SDCH support is not configured, pass through raw response.
- if (!request()->context()->sdch_manager())
- return upstream;
- types.push_back(SourceStream::TYPE_SDCH);
- } else {
- // Unknown encoding type. Pass through raw response body.
return upstream;
}
+ switch (source_type) {
+ case SourceStream::TYPE_BROTLI:
+ case SourceStream::TYPE_DEFLATE:
+ case SourceStream::TYPE_GZIP:
+ case SourceStream::TYPE_SDCH:
+ types.push_back(source_type);
+ break;
+ case SourceStream::TYPE_NONE:
+ // Identity encoding type. Pass through raw response body.
+ return upstream;
+ default:
+ // Unknown encoding type. Pass through raw response body.
+ // Despite of reporting to UMA, request will not be canceled; though
+ // it is expected that user will see malformed / garbage response.
+ FilterSourceStream::ReportContentDecodingFailed(
+ FilterSourceStream::TYPE_UNKNOWN);
+ return upstream;
+ }
}
// Sdch specific hacks:
@@ -1119,6 +1122,8 @@ std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() {
break;
case SourceStream::TYPE_NONE:
case SourceStream::TYPE_INVALID:
+ case SourceStream::TYPE_REJECTED:
+ case SourceStream::TYPE_UNKNOWN:
case SourceStream::TYPE_MAX:
NOTREACHED();
return nullptr;

Powered by Google App Engine
This is Rietveld 408576698