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 <utility> | 14 #include <utility> |
14 | 15 |
15 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
18 #include "base/pickle.h" | 19 #include "base/pickle.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 // header data, so we build a map from header name to generated header lines. | 450 // header data, so we build a map from header name to generated header lines. |
450 // to preserve the order of the original headers, the actual values are kept | 451 // to preserve the order of the original headers, the actual values are kept |
451 // in a separate list. finally, the list of headers is flattened to form | 452 // in a separate list. finally, the list of headers is flattened to form |
452 // the normalized block of headers. | 453 // the normalized block of headers. |
453 // | 454 // |
454 // NOTE: We take special care to preserve the whitespace around any commas | 455 // NOTE: We take special care to preserve the whitespace around any commas |
455 // that may occur in the original response headers. Because our consumer may | 456 // that may occur in the original response headers. Because our consumer may |
456 // be a web app, we cannot be certain of the semantics of commas despite the | 457 // be a web app, we cannot be certain of the semantics of commas despite the |
457 // fact that RFC 2616 says that they should be regarded as value separators. | 458 // fact that RFC 2616 says that they should be regarded as value separators. |
458 // | 459 // |
459 typedef base::hash_map<std::string, size_t> HeadersMap; | 460 using HeadersMap = std::unordered_map<std::string, size_t>; |
460 HeadersMap headers_map; | 461 HeadersMap headers_map; |
461 HeadersMap::iterator iter = headers_map.end(); | 462 HeadersMap::iterator iter = headers_map.end(); |
462 | 463 |
463 std::vector<std::string> headers; | 464 std::vector<std::string> headers; |
464 | 465 |
465 for (size_t i = 0; i < parsed_.size(); ++i) { | 466 for (size_t i = 0; i < parsed_.size(); ++i) { |
466 DCHECK(!parsed_[i].is_continuation()); | 467 DCHECK(!parsed_[i].is_continuation()); |
467 | 468 |
468 std::string name(parsed_[i].name_begin, parsed_[i].name_end); | 469 std::string name(parsed_[i].name_begin, parsed_[i].name_end); |
469 std::string lower_name = base::ToLowerASCII(name); | 470 std::string lower_name = base::ToLowerASCII(name); |
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 return true; | 1452 return true; |
1452 } | 1453 } |
1453 | 1454 |
1454 bool HttpResponseHeaders::IsChunkEncoded() const { | 1455 bool HttpResponseHeaders::IsChunkEncoded() const { |
1455 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1456 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
1456 return GetHttpVersion() >= HttpVersion(1, 1) && | 1457 return GetHttpVersion() >= HttpVersion(1, 1) && |
1457 HasHeaderValue("Transfer-Encoding", "chunked"); | 1458 HasHeaderValue("Transfer-Encoding", "chunked"); |
1458 } | 1459 } |
1459 | 1460 |
1460 } // namespace net | 1461 } // namespace net |
OLD | NEW |