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

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

Issue 1604011: Use HttpRequestHeaders for extra_headers. (Closed)
Patch Set: Address eroman comments. Created 10 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 unified diff | Download patch
« no previous file with comments | « net/http/http_vary_data.h ('k') | net/http/http_vary_data_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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "net/http/http_vary_data.h" 5 #include "net/http/http_vary_data.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "net/http/http_request_headers.h"
11 #include "net/http/http_request_info.h" 12 #include "net/http/http_request_info.h"
12 #include "net/http/http_response_headers.h" 13 #include "net/http/http_response_headers.h"
13 #include "net/http/http_util.h" 14 #include "net/http/http_util.h"
14 15
15 namespace net { 16 namespace net {
16 17
17 HttpVaryData::HttpVaryData() : is_valid_(false) { 18 HttpVaryData::HttpVaryData() : is_valid_(false) {
18 } 19 }
19 20
20 bool HttpVaryData::Init(const HttpRequestInfo& request_info, 21 bool HttpVaryData::Init(const HttpRequestInfo& request_info,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 91 }
91 return memcmp(&new_vary_data.request_digest_, &request_digest_, 92 return memcmp(&new_vary_data.request_digest_, &request_digest_,
92 sizeof(request_digest_)) == 0; 93 sizeof(request_digest_)) == 0;
93 } 94 }
94 95
95 // static 96 // static
96 std::string HttpVaryData::GetRequestValue( 97 std::string HttpVaryData::GetRequestValue(
97 const HttpRequestInfo& request_info, 98 const HttpRequestInfo& request_info,
98 const std::string& request_header) { 99 const std::string& request_header) {
99 // Some special cases: 100 // Some special cases:
100 if (LowerCaseEqualsASCII(request_header, "referer")) 101 if (!base::strcasecmp(request_header.c_str(), HttpRequestHeaders::kReferer))
101 return request_info.referrer.spec(); 102 return request_info.referrer.spec();
102 if (LowerCaseEqualsASCII(request_header, "user-agent"))
103 return request_info.user_agent;
104
105 std::string result;
106
107 // Check extra headers:
108 HttpUtil::HeadersIterator it(request_info.extra_headers.begin(),
109 request_info.extra_headers.end(),
110 "\r\n");
111 while (it.GetNext()) {
112 size_t name_len = it.name_end() - it.name_begin();
113 if (request_header.size() == name_len &&
114 std::equal(it.name_begin(), it.name_end(), request_header.begin(),
115 CaseInsensitiveCompare<char>())) {
116 if (!result.empty())
117 result.append(1, ',');
118 result.append(it.values());
119 }
120 }
121 103
122 // Unfortunately, we do not have access to all of the request headers at this 104 // Unfortunately, we do not have access to all of the request headers at this
123 // point. Most notably, we do not have access to an Authorization header if 105 // point. Most notably, we do not have access to an Authorization header if
124 // one will be added to the request. 106 // one will be added to the request.
125 107
126 return result; 108 std::string result;
109 if (request_info.extra_headers.GetHeader(request_header, &result))
110 return result;
111
112 return "";
127 } 113 }
128 114
129 // static 115 // static
130 void HttpVaryData::AddField(const HttpRequestInfo& request_info, 116 void HttpVaryData::AddField(const HttpRequestInfo& request_info,
131 const std::string& request_header, 117 const std::string& request_header,
132 MD5Context* ctx) { 118 MD5Context* ctx) {
133 std::string request_value = GetRequestValue(request_info, request_header); 119 std::string request_value = GetRequestValue(request_info, request_header);
134 120
135 // Append a character that cannot appear in the request header line so that we 121 // Append a character that cannot appear in the request header line so that we
136 // protect against case where the concatenation of two request headers could 122 // protect against case where the concatenation of two request headers could
137 // look the same for a variety of values for the individual request headers. 123 // look the same for a variety of values for the individual request headers.
138 // For example, "foo: 12\nbar: 3" looks like "foo: 1\nbar: 23" otherwise. 124 // For example, "foo: 12\nbar: 3" looks like "foo: 1\nbar: 23" otherwise.
139 request_value.append(1, '\n'); 125 request_value.append(1, '\n');
140 126
141 MD5Update(ctx, request_value.data(), request_value.size()); 127 MD5Update(ctx, request_value.data(), request_value.size());
142 } 128 }
143 129
144 } // namespace net 130 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_vary_data.h ('k') | net/http/http_vary_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698