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

Side by Side Diff: trunk/src/net/http/http_response_headers.cc

Issue 474483002: Revert 289312 "Move StringToUpperASCII and LowerCaseEqualsASCII ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/net/http/http_log_util.cc ('k') | trunk/src/net/http/http_security_headers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The rules for header parsing were borrowed from Firefox: 5 // The rules for header parsing were borrowed from Firefox:
6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp
7 // The rules for parsing content-types were also borrowed from Firefox: 7 // The rules for parsing content-types were also borrowed from Firefox:
8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834
9 9
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // this list: 91 // this list:
92 const char* const kNonUpdatedHeaderPrefixes[] = { 92 const char* const kNonUpdatedHeaderPrefixes[] = {
93 "content-", 93 "content-",
94 "x-content-", 94 "x-content-",
95 "x-webkit-" 95 "x-webkit-"
96 }; 96 };
97 97
98 bool ShouldUpdateHeader(const std::string::const_iterator& name_begin, 98 bool ShouldUpdateHeader(const std::string::const_iterator& name_begin,
99 const std::string::const_iterator& name_end) { 99 const std::string::const_iterator& name_end) {
100 for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) { 100 for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) {
101 if (base::LowerCaseEqualsASCII(name_begin, name_end, 101 if (LowerCaseEqualsASCII(name_begin, name_end, kNonUpdatedHeaders[i]))
102 kNonUpdatedHeaders[i]))
103 return false; 102 return false;
104 } 103 }
105 for (size_t i = 0; i < arraysize(kNonUpdatedHeaderPrefixes); ++i) { 104 for (size_t i = 0; i < arraysize(kNonUpdatedHeaderPrefixes); ++i) {
106 if (StartsWithASCII(std::string(name_begin, name_end), 105 if (StartsWithASCII(std::string(name_begin, name_end),
107 kNonUpdatedHeaderPrefixes[i], false)) 106 kNonUpdatedHeaderPrefixes[i], false))
108 return false; 107 return false;
109 } 108 }
110 return true; 109 return true;
111 } 110 }
112 111
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // static 625 // static
627 HttpVersion HttpResponseHeaders::ParseVersion( 626 HttpVersion HttpResponseHeaders::ParseVersion(
628 std::string::const_iterator line_begin, 627 std::string::const_iterator line_begin,
629 std::string::const_iterator line_end) { 628 std::string::const_iterator line_end) {
630 std::string::const_iterator p = line_begin; 629 std::string::const_iterator p = line_begin;
631 630
632 // RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT 631 // RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
633 // TODO: (1*DIGIT apparently means one or more digits, but we only handle 1). 632 // TODO: (1*DIGIT apparently means one or more digits, but we only handle 1).
634 // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1. 633 // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1.
635 634
636 if ((line_end - p < 4) || !base::LowerCaseEqualsASCII(p, p + 4, "http")) { 635 if ((line_end - p < 4) || !LowerCaseEqualsASCII(p, p + 4, "http")) {
637 DVLOG(1) << "missing status line"; 636 DVLOG(1) << "missing status line";
638 return HttpVersion(); 637 return HttpVersion();
639 } 638 }
640 639
641 p += 4; 640 p += 4;
642 641
643 if (p >= line_end || *p != '/') { 642 if (p >= line_end || *p != '/') {
644 DVLOG(1) << "missing version"; 643 DVLOG(1) << "missing version";
645 return HttpVersion(); 644 return HttpVersion();
646 } 645 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 bool HttpResponseHeaders::GetCacheControlDirective(const StringPiece& directive, 756 bool HttpResponseHeaders::GetCacheControlDirective(const StringPiece& directive,
758 TimeDelta* result) const { 757 TimeDelta* result) const {
759 StringPiece name("cache-control"); 758 StringPiece name("cache-control");
760 std::string value; 759 std::string value;
761 760
762 size_t directive_size = directive.size(); 761 size_t directive_size = directive.size();
763 762
764 void* iter = NULL; 763 void* iter = NULL;
765 while (EnumerateHeader(&iter, name, &value)) { 764 while (EnumerateHeader(&iter, name, &value)) {
766 if (value.size() > directive_size + 1 && 765 if (value.size() > directive_size + 1 &&
767 base::LowerCaseEqualsASCII(value.begin(), 766 LowerCaseEqualsASCII(value.begin(),
768 value.begin() + directive_size, 767 value.begin() + directive_size,
769 directive.begin()) && 768 directive.begin()) &&
770 value[directive_size] == '=') { 769 value[directive_size] == '=') {
771 int64 seconds; 770 int64 seconds;
772 base::StringToInt64( 771 base::StringToInt64(
773 StringPiece(value.begin() + directive_size + 1, value.end()), 772 StringPiece(value.begin() + directive_size + 1, value.end()),
774 &seconds); 773 &seconds);
775 *result = TimeDelta::FromSeconds(seconds); 774 *result = TimeDelta::FromSeconds(seconds);
776 return true; 775 return true;
777 } 776 }
778 } 777 }
779 778
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 // meaningful when we don't know that this response was from a proxy, but 1177 // meaningful when we don't know that this response was from a proxy, but
1179 // Mozilla also does this, so we'll do the same. 1178 // Mozilla also does this, so we'll do the same.
1180 std::string connection_val; 1179 std::string connection_val;
1181 if (!EnumerateHeader(NULL, "connection", &connection_val)) 1180 if (!EnumerateHeader(NULL, "connection", &connection_val))
1182 EnumerateHeader(NULL, "proxy-connection", &connection_val); 1181 EnumerateHeader(NULL, "proxy-connection", &connection_val);
1183 1182
1184 bool keep_alive; 1183 bool keep_alive;
1185 1184
1186 if (http_version_ == HttpVersion(1, 0)) { 1185 if (http_version_ == HttpVersion(1, 0)) {
1187 // HTTP/1.0 responses default to NOT keep-alive 1186 // HTTP/1.0 responses default to NOT keep-alive
1188 keep_alive = base::LowerCaseEqualsASCII(connection_val, "keep-alive"); 1187 keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive");
1189 } else { 1188 } else {
1190 // HTTP/1.1 responses default to keep-alive 1189 // HTTP/1.1 responses default to keep-alive
1191 keep_alive = !base::LowerCaseEqualsASCII(connection_val, "close"); 1190 keep_alive = !LowerCaseEqualsASCII(connection_val, "close");
1192 } 1191 }
1193 1192
1194 return keep_alive; 1193 return keep_alive;
1195 } 1194 }
1196 1195
1197 bool HttpResponseHeaders::HasStrongValidators() const { 1196 bool HttpResponseHeaders::HasStrongValidators() const {
1198 std::string etag_header; 1197 std::string etag_header;
1199 EnumerateHeader(NULL, "etag", &etag_header); 1198 EnumerateHeader(NULL, "etag", &etag_header);
1200 std::string last_modified_header; 1199 std::string last_modified_header;
1201 EnumerateHeader(NULL, "Last-Modified", &last_modified_header); 1200 EnumerateHeader(NULL, "Last-Modified", &last_modified_header);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 size_t space_position = content_range_spec.find(' '); 1255 size_t space_position = content_range_spec.find(' ');
1257 if (space_position == std::string::npos) 1256 if (space_position == std::string::npos)
1258 return false; 1257 return false;
1259 1258
1260 // Invalid header if it doesn't contain "bytes-unit". 1259 // Invalid header if it doesn't contain "bytes-unit".
1261 std::string::const_iterator content_range_spec_begin = 1260 std::string::const_iterator content_range_spec_begin =
1262 content_range_spec.begin(); 1261 content_range_spec.begin();
1263 std::string::const_iterator content_range_spec_end = 1262 std::string::const_iterator content_range_spec_end =
1264 content_range_spec.begin() + space_position; 1263 content_range_spec.begin() + space_position;
1265 HttpUtil::TrimLWS(&content_range_spec_begin, &content_range_spec_end); 1264 HttpUtil::TrimLWS(&content_range_spec_begin, &content_range_spec_end);
1266 if (!base::LowerCaseEqualsASCII(content_range_spec_begin, 1265 if (!LowerCaseEqualsASCII(content_range_spec_begin,
1267 content_range_spec_end, 1266 content_range_spec_end,
1268 "bytes")) { 1267 "bytes")) {
1269 return false; 1268 return false;
1270 } 1269 }
1271 1270
1272 size_t slash_position = content_range_spec.find('/', space_position + 1); 1271 size_t slash_position = content_range_spec.find('/', space_position + 1);
1273 if (slash_position == std::string::npos) 1272 if (slash_position == std::string::npos)
1274 return false; 1273 return false;
1275 1274
1276 // Obtain the part behind the space and before slash. 1275 // Obtain the part behind the space and before slash.
1277 std::string::const_iterator byte_range_resp_spec_begin = 1276 std::string::const_iterator byte_range_resp_spec_begin =
1278 content_range_spec.begin() + space_position + 1; 1277 content_range_spec.begin() + space_position + 1;
1279 std::string::const_iterator byte_range_resp_spec_end = 1278 std::string::const_iterator byte_range_resp_spec_end =
1280 content_range_spec.begin() + slash_position; 1279 content_range_spec.begin() + slash_position;
1281 HttpUtil::TrimLWS(&byte_range_resp_spec_begin, &byte_range_resp_spec_end); 1280 HttpUtil::TrimLWS(&byte_range_resp_spec_begin, &byte_range_resp_spec_end);
1282 1281
1283 // Parse the byte-range-resp-spec part. 1282 // Parse the byte-range-resp-spec part.
1284 std::string byte_range_resp_spec(byte_range_resp_spec_begin, 1283 std::string byte_range_resp_spec(byte_range_resp_spec_begin,
1285 byte_range_resp_spec_end); 1284 byte_range_resp_spec_end);
1286 // If byte-range-resp-spec != "*". 1285 // If byte-range-resp-spec != "*".
1287 if (!base::LowerCaseEqualsASCII(byte_range_resp_spec, "*")) { 1286 if (!LowerCaseEqualsASCII(byte_range_resp_spec, "*")) {
1288 size_t minus_position = byte_range_resp_spec.find('-'); 1287 size_t minus_position = byte_range_resp_spec.find('-');
1289 if (minus_position != std::string::npos) { 1288 if (minus_position != std::string::npos) {
1290 // Obtain first-byte-pos. 1289 // Obtain first-byte-pos.
1291 std::string::const_iterator first_byte_pos_begin = 1290 std::string::const_iterator first_byte_pos_begin =
1292 byte_range_resp_spec.begin(); 1291 byte_range_resp_spec.begin();
1293 std::string::const_iterator first_byte_pos_end = 1292 std::string::const_iterator first_byte_pos_end =
1294 byte_range_resp_spec.begin() + minus_position; 1293 byte_range_resp_spec.begin() + minus_position;
1295 HttpUtil::TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); 1294 HttpUtil::TrimLWS(&first_byte_pos_begin, &first_byte_pos_end);
1296 1295
1297 bool ok = base::StringToInt64(StringPiece(first_byte_pos_begin, 1296 bool ok = base::StringToInt64(StringPiece(first_byte_pos_begin,
(...skipping 23 matching lines...) Expand all
1321 } 1320 }
1322 1321
1323 // Parse the instance-length part. 1322 // Parse the instance-length part.
1324 // If instance-length == "*". 1323 // If instance-length == "*".
1325 std::string::const_iterator instance_length_begin = 1324 std::string::const_iterator instance_length_begin =
1326 content_range_spec.begin() + slash_position + 1; 1325 content_range_spec.begin() + slash_position + 1;
1327 std::string::const_iterator instance_length_end = 1326 std::string::const_iterator instance_length_end =
1328 content_range_spec.end(); 1327 content_range_spec.end();
1329 HttpUtil::TrimLWS(&instance_length_begin, &instance_length_end); 1328 HttpUtil::TrimLWS(&instance_length_begin, &instance_length_end);
1330 1329
1331 if (base::LowerCaseEqualsASCII(instance_length_begin, instance_length_end, 1330 if (LowerCaseEqualsASCII(instance_length_begin, instance_length_end, "*")) {
1332 "*")) {
1333 return false; 1331 return false;
1334 } else if (!base::StringToInt64(StringPiece(instance_length_begin, 1332 } else if (!base::StringToInt64(StringPiece(instance_length_begin,
1335 instance_length_end), 1333 instance_length_end),
1336 instance_length)) { 1334 instance_length)) {
1337 *instance_length = -1; 1335 *instance_length = -1;
1338 return false; 1336 return false;
1339 } 1337 }
1340 1338
1341 // We have all the values; let's verify that they make sense for a 206 1339 // We have all the values; let's verify that they make sense for a 206
1342 // response. 1340 // response.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 return true; 1397 return true;
1400 } 1398 }
1401 1399
1402 bool HttpResponseHeaders::IsChunkEncoded() const { 1400 bool HttpResponseHeaders::IsChunkEncoded() const {
1403 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. 1401 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
1404 return GetHttpVersion() >= HttpVersion(1, 1) && 1402 return GetHttpVersion() >= HttpVersion(1, 1) &&
1405 HasHeaderValue("Transfer-Encoding", "chunked"); 1403 HasHeaderValue("Transfer-Encoding", "chunked");
1406 } 1404 }
1407 1405
1408 } // namespace net 1406 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/http/http_log_util.cc ('k') | trunk/src/net/http/http_security_headers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698