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 // ares are not sent in practice, to reduce upload size & memory use. | |
wtc
2011/01/26 19:03:11
Typo: remove 'ares', or change it to 'ones'
gavinp
2011/01/27 00:04:36
Done.
| |
93 | |
94 enum { kHistogramMinHttpResponseCode = 100, | |
95 kHistogramMaxHttpResponseCode = 599, | |
wtc
2011/01/26 19:03:11
The formatting is still wrong. It should be:
enu
jar (doing other things)
2011/01/26 21:33:14
nit: On Chrome, we use MACRO_STYLE_NAMING for enum
gavinp
2011/01/27 00:04:36
Done.
gavinp
2011/01/27 00:04:36
Done.
| |
96 }; | |
97 | |
98 std::vector<int> GetAllHttpResponseCodes() { | |
99 std::vector<int> codes; | |
100 codes.reserve( | |
101 kHistogramMaxHttpResponseCode - kHistogramMinHttpResponseCode + 2); | |
102 // The 0 histogram value is used to return results that are not in the | |
103 // range [kHistogramMinHttpResponseCode, kHistogramMaxHttpResponseCode]. | |
wtc
2011/01/26 19:03:11
I see that you already explained the 0 histogram v
gavinp
2011/01/27 00:04:36
Done.
| |
104 codes.push_back(0); | |
105 for (int i = kHistogramMinHttpResponseCode; | |
106 i <= kHistogramMaxHttpResponseCode; ++i) | |
107 codes.push_back(i); | |
108 return codes; | |
109 } | |
110 | |
111 int MapHttpResponseCode(int code) { | |
112 if (kHistogramMinHttpResponseCode <= code && | |
113 code <= kHistogramMaxHttpResponseCode) | |
114 return code; | |
115 return 0; | |
116 } | |
117 | |
88 } // namespace | 118 } // namespace |
89 | 119 |
90 struct HttpResponseHeaders::ParsedHeader { | 120 struct HttpResponseHeaders::ParsedHeader { |
91 // A header "continuation" contains only a subsequent value for the | 121 // A header "continuation" contains only a subsequent value for the |
92 // preceding header. (Header values are comma separated.) | 122 // preceding header. (Header values are comma separated.) |
93 bool is_continuation() const { return name_begin == name_end; } | 123 bool is_continuation() const { return name_begin == name_end; } |
94 | 124 |
95 std::string::const_iterator name_begin; | 125 std::string::const_iterator name_begin; |
96 std::string::const_iterator name_end; | 126 std::string::const_iterator name_end; |
97 std::string::const_iterator value_begin; | 127 std::string::const_iterator value_begin; |
98 std::string::const_iterator value_end; | 128 std::string::const_iterator value_end; |
99 }; | 129 }; |
100 | 130 |
101 //----------------------------------------------------------------------------- | 131 //----------------------------------------------------------------------------- |
102 | 132 |
103 HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input) | 133 HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input) |
104 : response_code_(-1) { | 134 : response_code_(-1) { |
105 Parse(raw_input); | 135 Parse(raw_input); |
136 | |
137 // The most important thing to do with this histogram is find out the | |
138 // existence of unusual HTTP response codes. As it happens right now, | |
139 // there aren't double-constructions of response headers using this | |
140 // constructor, so our counts should also be accurate, without | |
141 // instantiating the histogram in two places. | |
wtc
2011/01/26 19:03:11
You should also explain why the other constructors
gavinp
2011/01/27 00:04:36
Done.
| |
142 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.HttpResponseCode", | |
143 MapHttpResponseCode(response_code_), | |
144 // Note the third argument is only | |
145 // evaluated once, see macro def'n | |
146 // for details. | |
147 GetAllHttpResponseCodes()); | |
106 } | 148 } |
107 | 149 |
108 HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter) | 150 HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter) |
109 : response_code_(-1) { | 151 : response_code_(-1) { |
110 std::string raw_input; | 152 std::string raw_input; |
111 if (pickle.ReadString(iter, &raw_input)) | 153 if (pickle.ReadString(iter, &raw_input)) |
112 Parse(raw_input); | 154 Parse(raw_input); |
113 } | 155 } |
114 | 156 |
115 void HttpResponseHeaders::Persist(Pickle* pickle, PersistOptions options) { | 157 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 | 1249 // We have all the values; let's verify that they make sense for a 206 |
1208 // response. | 1250 // response. |
1209 if (*first_byte_position < 0 || *last_byte_position < 0 || | 1251 if (*first_byte_position < 0 || *last_byte_position < 0 || |
1210 *instance_length < 0 || *instance_length - 1 < *last_byte_position) | 1252 *instance_length < 0 || *instance_length - 1 < *last_byte_position) |
1211 return false; | 1253 return false; |
1212 | 1254 |
1213 return true; | 1255 return true; |
1214 } | 1256 } |
1215 | 1257 |
1216 } // namespace net | 1258 } // namespace net |
OLD | NEW |