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 // 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 #include <unordered_map> | 13 #include <unordered_map> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/ptr_util.h" |
18 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
19 #include "base/pickle.h" | 20 #include "base/pickle.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
25 #include "base/values.h" | 26 #include "base/values.h" |
26 #include "net/base/escape.h" | 27 #include "net/base/escape.h" |
27 #include "net/base/parse_number.h" | 28 #include "net/base/parse_number.h" |
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 return false; | 1258 return false; |
1258 } | 1259 } |
1259 | 1260 |
1260 return HttpUtil::ParseContentRangeHeaderFor206( | 1261 return HttpUtil::ParseContentRangeHeaderFor206( |
1261 content_range_spec, first_byte_position, last_byte_position, | 1262 content_range_spec, first_byte_position, last_byte_position, |
1262 instance_length); | 1263 instance_length); |
1263 } | 1264 } |
1264 | 1265 |
1265 std::unique_ptr<base::Value> HttpResponseHeaders::NetLogCallback( | 1266 std::unique_ptr<base::Value> HttpResponseHeaders::NetLogCallback( |
1266 NetLogCaptureMode capture_mode) const { | 1267 NetLogCaptureMode capture_mode) const { |
1267 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 1268 auto dict = base::MakeUnique<base::DictionaryValue>(); |
1268 base::ListValue* headers = new base::ListValue(); | 1269 auto headers = base::MakeUnique<base::ListValue>(); |
1269 headers->AppendString(EscapeNonASCII(GetStatusLine())); | 1270 headers->AppendString(EscapeNonASCII(GetStatusLine())); |
1270 size_t iterator = 0; | 1271 size_t iterator = 0; |
1271 std::string name; | 1272 std::string name; |
1272 std::string value; | 1273 std::string value; |
1273 while (EnumerateHeaderLines(&iterator, &name, &value)) { | 1274 while (EnumerateHeaderLines(&iterator, &name, &value)) { |
1274 std::string log_value = | 1275 std::string log_value = |
1275 ElideHeaderValueForNetLog(capture_mode, name, value); | 1276 ElideHeaderValueForNetLog(capture_mode, name, value); |
1276 std::string escaped_name = EscapeNonASCII(name); | 1277 std::string escaped_name = EscapeNonASCII(name); |
1277 std::string escaped_value = EscapeNonASCII(log_value); | 1278 std::string escaped_value = EscapeNonASCII(log_value); |
1278 headers->AppendString(base::StringPrintf("%s: %s", escaped_name.c_str(), | 1279 headers->AppendString(base::StringPrintf("%s: %s", escaped_name.c_str(), |
1279 escaped_value.c_str())); | 1280 escaped_value.c_str())); |
1280 } | 1281 } |
1281 dict->Set("headers", headers); | 1282 dict->Set("headers", std::move(headers)); |
1282 return std::move(dict); | 1283 return std::move(dict); |
1283 } | 1284 } |
1284 | 1285 |
1285 // static | 1286 // static |
1286 bool HttpResponseHeaders::FromNetLogParam( | 1287 bool HttpResponseHeaders::FromNetLogParam( |
1287 const base::Value* event_param, | 1288 const base::Value* event_param, |
1288 scoped_refptr<HttpResponseHeaders>* http_response_headers) { | 1289 scoped_refptr<HttpResponseHeaders>* http_response_headers) { |
1289 *http_response_headers = NULL; | 1290 *http_response_headers = NULL; |
1290 | 1291 |
1291 const base::DictionaryValue* dict = NULL; | 1292 const base::DictionaryValue* dict = NULL; |
(...skipping 21 matching lines...) Expand all Loading... |
1313 return true; | 1314 return true; |
1314 } | 1315 } |
1315 | 1316 |
1316 bool HttpResponseHeaders::IsChunkEncoded() const { | 1317 bool HttpResponseHeaders::IsChunkEncoded() const { |
1317 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1318 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
1318 return GetHttpVersion() >= HttpVersion(1, 1) && | 1319 return GetHttpVersion() >= HttpVersion(1, 1) && |
1319 HasHeaderValue("Transfer-Encoding", "chunked"); | 1320 HasHeaderValue("Transfer-Encoding", "chunked"); |
1320 } | 1321 } |
1321 | 1322 |
1322 } // namespace net | 1323 } // namespace net |
OLD | NEW |