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

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

Issue 12224008: Add to the list of HTTP headers that don't overwrite in 304 responses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | « no previous file | net/http/http_response_headers_unittest.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // response headers. This list is based on Mozilla's nsHttpResponseHead.cpp. 71 // response headers. This list is based on Mozilla's nsHttpResponseHead.cpp.
72 const char* const kNonUpdatedHeaders[] = { 72 const char* const kNonUpdatedHeaders[] = {
73 "connection", 73 "connection",
74 "proxy-connection", 74 "proxy-connection",
75 "keep-alive", 75 "keep-alive",
76 "www-authenticate", 76 "www-authenticate",
77 "proxy-authenticate", 77 "proxy-authenticate",
78 "trailer", 78 "trailer",
79 "transfer-encoding", 79 "transfer-encoding",
80 "upgrade", 80 "upgrade",
81 // these should never change:
82 "content-location",
83 "content-md5",
84 "etag", 81 "etag",
85 // assume cache-control: no-transform 82 "x-frame-options",
86 "content-encoding", 83 "x-xss-protection",
87 "content-range", 84 };
88 "content-type", 85
89 // some broken microsoft servers send 'content-length: 0' with 304s 86 // Some header prefixes mean "Don't copy this header from a 304 response.".
90 "content-length" 87 // Rather than listing all the relevant headers, we can consolidate them into
88 // this list:
89 const char* const kNonUpdatedHeaderPrefixes[] = {
agl 2013/02/05 14:41:55 Minor sadness at the extra indirection and relocat
Mike West 2013/02/05 15:59:39 Filed https://code.google.com/p/chromium/issues/de
90 "content-",
91 "x-content-",
92 "x-webkit-"
91 }; 93 };
92 94
93 bool ShouldUpdateHeader(const std::string::const_iterator& name_begin, 95 bool ShouldUpdateHeader(const std::string::const_iterator& name_begin,
94 const std::string::const_iterator& name_end) { 96 const std::string::const_iterator& name_end) {
95 for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) { 97 for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) {
96 if (LowerCaseEqualsASCII(name_begin, name_end, kNonUpdatedHeaders[i])) 98 if (LowerCaseEqualsASCII(name_begin, name_end, kNonUpdatedHeaders[i]))
97 return false; 99 return false;
98 } 100 }
101 for (size_t i = 0; i < arraysize(kNonUpdatedHeaderPrefixes); ++i) {
102 if (StartsWithASCII(std::string(name_begin, name_end),
agl 2013/02/05 14:41:55 Yet more sadness for there not being a StartsWithA
Mike West 2013/02/05 15:59:39 Indeed. I looked briefly at adding such a beast, b
103 kNonUpdatedHeaderPrefixes[i], false))
104 return false;
105 }
99 return true; 106 return true;
100 } 107 }
101 108
102 void CheckDoesNotHaveEmbededNulls(const std::string& str) { 109 void CheckDoesNotHaveEmbededNulls(const std::string& str) {
103 // Care needs to be taken when adding values to the raw headers string to 110 // Care needs to be taken when adding values to the raw headers string to
104 // make sure it does not contain embeded NULLs. Any embeded '\0' may be 111 // make sure it does not contain embeded NULLs. Any embeded '\0' may be
105 // understood as line terminators and change how header lines get tokenized. 112 // understood as line terminators and change how header lines get tokenized.
106 CHECK(str.find('\0') == std::string::npos); 113 CHECK(str.find('\0') == std::string::npos);
107 } 114 }
108 115
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 return true; 1343 return true;
1337 } 1344 }
1338 1345
1339 bool HttpResponseHeaders::IsChunkEncoded() const { 1346 bool HttpResponseHeaders::IsChunkEncoded() const {
1340 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. 1347 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
1341 return GetHttpVersion() >= HttpVersion(1, 1) && 1348 return GetHttpVersion() >= HttpVersion(1, 1) &&
1342 HasHeaderValue("Transfer-Encoding", "chunked"); 1349 HasHeaderValue("Transfer-Encoding", "chunked");
1343 } 1350 }
1344 1351
1345 } // namespace net 1352 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698