| OLD | NEW |
| 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 #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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 bool HttpVaryData::MatchesRequest( | 82 bool HttpVaryData::MatchesRequest( |
| 83 const HttpRequestInfo& request_info, | 83 const HttpRequestInfo& request_info, |
| 84 const HttpResponseHeaders& cached_response_headers) const { | 84 const HttpResponseHeaders& cached_response_headers) const { |
| 85 HttpVaryData new_vary_data; | 85 HttpVaryData new_vary_data; |
| 86 if (!new_vary_data.Init(request_info, cached_response_headers)) { | 86 if (!new_vary_data.Init(request_info, cached_response_headers)) { |
| 87 // This shouldn't happen provided the same response headers passed here | 87 // This shouldn't happen provided the same response headers passed here |
| 88 // were also used when initializing |this|. | 88 // were also used when initializing |this|. |
| 89 NOTREACHED(); | 89 NOTREACHED(); |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| 92 return memcmp(&new_vary_data.request_digest_, &request_digest_, | 92 return memcmp(&new_vary_data.request_digest_, |
| 93 &request_digest_, |
| 93 sizeof(request_digest_)) == 0; | 94 sizeof(request_digest_)) == 0; |
| 94 } | 95 } |
| 95 | 96 |
| 96 // static | 97 // static |
| 97 std::string HttpVaryData::GetRequestValue( | 98 std::string HttpVaryData::GetRequestValue(const HttpRequestInfo& request_info, |
| 98 const HttpRequestInfo& request_info, | 99 const std::string& request_header) { |
| 99 const std::string& request_header) { | |
| 100 // Unfortunately, we do not have access to all of the request headers at this | 100 // Unfortunately, we do not have access to all of the request headers at this |
| 101 // point. Most notably, we do not have access to an Authorization header if | 101 // point. Most notably, we do not have access to an Authorization header if |
| 102 // one will be added to the request. | 102 // one will be added to the request. |
| 103 | 103 |
| 104 std::string result; | 104 std::string result; |
| 105 if (request_info.extra_headers.GetHeader(request_header, &result)) | 105 if (request_info.extra_headers.GetHeader(request_header, &result)) |
| 106 return result; | 106 return result; |
| 107 | 107 |
| 108 return std::string(); | 108 return std::string(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // static | 111 // static |
| 112 void HttpVaryData::AddField(const HttpRequestInfo& request_info, | 112 void HttpVaryData::AddField(const HttpRequestInfo& request_info, |
| 113 const std::string& request_header, | 113 const std::string& request_header, |
| 114 base::MD5Context* ctx) { | 114 base::MD5Context* ctx) { |
| 115 std::string request_value = GetRequestValue(request_info, request_header); | 115 std::string request_value = GetRequestValue(request_info, request_header); |
| 116 | 116 |
| 117 // Append a character that cannot appear in the request header line so that we | 117 // Append a character that cannot appear in the request header line so that we |
| 118 // protect against case where the concatenation of two request headers could | 118 // protect against case where the concatenation of two request headers could |
| 119 // look the same for a variety of values for the individual request headers. | 119 // look the same for a variety of values for the individual request headers. |
| 120 // For example, "foo: 12\nbar: 3" looks like "foo: 1\nbar: 23" otherwise. | 120 // For example, "foo: 12\nbar: 3" looks like "foo: 1\nbar: 23" otherwise. |
| 121 request_value.append(1, '\n'); | 121 request_value.append(1, '\n'); |
| 122 | 122 |
| 123 base::MD5Update(ctx, request_value); | 123 base::MD5Update(ctx, request_value); |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace net | 126 } // namespace net |
| OLD | NEW |