OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" |
15 #include "base/pickle.h" | 16 #include "base/pickle.h" |
16 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
19 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
20 #include "net/http/http_util.h" | 21 #include "net/http/http_util.h" |
21 | 22 |
22 using base::Time; | 23 using base::Time; |
23 using base::TimeDelta; | 24 using base::TimeDelta; |
24 | 25 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 79 |
79 bool ShouldUpdateHeader(const std::string::const_iterator& name_begin, | 80 bool ShouldUpdateHeader(const std::string::const_iterator& name_begin, |
80 const std::string::const_iterator& name_end) { | 81 const std::string::const_iterator& name_end) { |
81 for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) { | 82 for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) { |
82 if (LowerCaseEqualsASCII(name_begin, name_end, kNonUpdatedHeaders[i])) | 83 if (LowerCaseEqualsASCII(name_begin, name_end, kNonUpdatedHeaders[i])) |
83 return false; | 84 return false; |
84 } | 85 } |
85 return true; | 86 return true; |
86 } | 87 } |
87 | 88 |
| 89 // Functions for histogram initialization. The code 0 is put in the |
| 90 // response map to track response codes that are invalid. |
| 91 // TODO(gavinp): Greatly prune the collected codes once we learn which |
| 92 // ones are not sent in practice, to reduce upload size & memory use. |
| 93 |
| 94 enum { |
| 95 HISTOGRAM_MIN_HTTP_RESPONSE_CODE = 100, |
| 96 HISTOGRAM_MAX_HTTP_RESPONSE_CODE = 599, |
| 97 }; |
| 98 |
| 99 std::vector<int> GetAllHttpResponseCodes() { |
| 100 std::vector<int> codes; |
| 101 codes.reserve( |
| 102 HISTOGRAM_MAX_HTTP_RESPONSE_CODE - HISTOGRAM_MIN_HTTP_RESPONSE_CODE + 2); |
| 103 codes.push_back(0); |
| 104 for (int i = HISTOGRAM_MIN_HTTP_RESPONSE_CODE; |
| 105 i <= HISTOGRAM_MAX_HTTP_RESPONSE_CODE; ++i) |
| 106 codes.push_back(i); |
| 107 return codes; |
| 108 } |
| 109 |
| 110 int MapHttpResponseCode(int code) { |
| 111 if (HISTOGRAM_MIN_HTTP_RESPONSE_CODE <= code && |
| 112 code <= HISTOGRAM_MAX_HTTP_RESPONSE_CODE) |
| 113 return code; |
| 114 return 0; |
| 115 } |
| 116 |
88 } // namespace | 117 } // namespace |
89 | 118 |
90 struct HttpResponseHeaders::ParsedHeader { | 119 struct HttpResponseHeaders::ParsedHeader { |
91 // A header "continuation" contains only a subsequent value for the | 120 // A header "continuation" contains only a subsequent value for the |
92 // preceding header. (Header values are comma separated.) | 121 // preceding header. (Header values are comma separated.) |
93 bool is_continuation() const { return name_begin == name_end; } | 122 bool is_continuation() const { return name_begin == name_end; } |
94 | 123 |
95 std::string::const_iterator name_begin; | 124 std::string::const_iterator name_begin; |
96 std::string::const_iterator name_end; | 125 std::string::const_iterator name_end; |
97 std::string::const_iterator value_begin; | 126 std::string::const_iterator value_begin; |
98 std::string::const_iterator value_end; | 127 std::string::const_iterator value_end; |
99 }; | 128 }; |
100 | 129 |
101 //----------------------------------------------------------------------------- | 130 //----------------------------------------------------------------------------- |
102 | 131 |
103 HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input) | 132 HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input) |
104 : response_code_(-1) { | 133 : response_code_(-1) { |
105 Parse(raw_input); | 134 Parse(raw_input); |
| 135 |
| 136 // The most important thing to do with this histogram is find out |
| 137 // the existence of unusual HTTP response codes. As it happens |
| 138 // right now, there aren't double-constructions of response headers |
| 139 // using this constructor, so our counts should also be accurate, |
| 140 // without instantiating the histogram in two places. It is also |
| 141 // important that this histogram not collect data in the other |
| 142 // constructor, which rebuilds an histogram from a pickle, since |
| 143 // that would actually create a double call between the original |
| 144 // HttpResponseHeader that was serialized, and initialization of the |
| 145 // new object from that pickle. |
| 146 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.HttpResponseCode", |
| 147 MapHttpResponseCode(response_code_), |
| 148 // Note the third argument is only |
| 149 // evaluated once, see macro |
| 150 // definition for details. |
| 151 GetAllHttpResponseCodes()); |
106 } | 152 } |
107 | 153 |
108 HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter) | 154 HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter) |
109 : response_code_(-1) { | 155 : response_code_(-1) { |
110 std::string raw_input; | 156 std::string raw_input; |
111 if (pickle.ReadString(iter, &raw_input)) | 157 if (pickle.ReadString(iter, &raw_input)) |
112 Parse(raw_input); | 158 Parse(raw_input); |
113 } | 159 } |
114 | 160 |
115 void HttpResponseHeaders::Persist(Pickle* pickle, PersistOptions options) { | 161 void HttpResponseHeaders::Persist(Pickle* pickle, PersistOptions options) { |
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 // We have all the values; let's verify that they make sense for a 206 | 1253 // We have all the values; let's verify that they make sense for a 206 |
1208 // response. | 1254 // response. |
1209 if (*first_byte_position < 0 || *last_byte_position < 0 || | 1255 if (*first_byte_position < 0 || *last_byte_position < 0 || |
1210 *instance_length < 0 || *instance_length - 1 < *last_byte_position) | 1256 *instance_length < 0 || *instance_length - 1 < *last_byte_position) |
1211 return false; | 1257 return false; |
1212 | 1258 |
1213 return true; | 1259 return true; |
1214 } | 1260 } |
1215 | 1261 |
1216 } // namespace net | 1262 } // namespace net |
OLD | NEW |