OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tools/balsa/balsa_headers.h" | 5 #include "net/tools/balsa/balsa_headers.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <ext/hash_set> | |
10 #include <string> | 9 #include <string> |
11 #include <utility> | 10 #include <utility> |
12 #include <vector> | 11 #include <vector> |
13 | 12 |
| 13 #include "base/containers/hash_tables.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/port.h" | 15 #include "base/port.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "net/tools/balsa/balsa_enums.h" | 18 #include "net/tools/balsa/balsa_enums.h" |
19 #include "net/tools/balsa/buffer_interface.h" | 19 #include "net/tools/balsa/buffer_interface.h" |
20 #include "net/tools/balsa/simple_buffer.h" | 20 #include "net/tools/balsa/simple_buffer.h" |
21 #include "third_party/tcmalloc/chromium/src/base/googleinit.h" | 21 #include "third_party/tcmalloc/chromium/src/base/googleinit.h" |
22 | 22 |
| 23 #if defined(COMPILER_MSVC) |
| 24 #include <string.h> |
| 25 #define snprintf _snprintf |
| 26 #define strncasecmp _strnicmp |
| 27 #else |
| 28 #include <strings.h> |
| 29 #endif |
| 30 |
23 namespace { | 31 namespace { |
24 | 32 |
25 const char kContentLength[] = "Content-Length"; | 33 const char kContentLength[] = "Content-Length"; |
26 const char kTransferEncoding[] = "Transfer-Encoding"; | 34 const char kTransferEncoding[] = "Transfer-Encoding"; |
27 const char kSpaceChar = ' '; | 35 const char kSpaceChar = ' '; |
28 | 36 |
29 __gnu_cxx::hash_set<base::StringPiece, | 37 #if defined(COMPILER_MSVC) |
30 net::StringPieceCaseHash, | 38 base::hash_set<base::StringPiece, |
31 net::StringPieceCaseEqual> g_multivalued_headers; | 39 net::StringPieceCaseCompare> g_multivalued_headers; |
| 40 #else |
| 41 base::hash_set<base::StringPiece, |
| 42 net::StringPieceCaseHash, |
| 43 net::StringPieceCaseEqual> g_multivalued_headers; |
| 44 #endif |
32 | 45 |
33 void InitMultivaluedHeaders() { | 46 void InitMultivaluedHeaders() { |
34 g_multivalued_headers.insert("accept"); | 47 g_multivalued_headers.insert("accept"); |
35 g_multivalued_headers.insert("accept-charset"); | 48 g_multivalued_headers.insert("accept-charset"); |
36 g_multivalued_headers.insert("accept-encoding"); | 49 g_multivalued_headers.insert("accept-encoding"); |
37 g_multivalued_headers.insert("accept-language"); | 50 g_multivalued_headers.insert("accept-language"); |
38 g_multivalued_headers.insert("accept-ranges"); | 51 g_multivalued_headers.insert("accept-ranges"); |
39 g_multivalued_headers.insert("allow"); | 52 g_multivalued_headers.insert("allow"); |
40 g_multivalued_headers.insert("cache-control"); | 53 g_multivalued_headers.insert("cache-control"); |
41 g_multivalued_headers.insert("connection"); | 54 g_multivalued_headers.insert("connection"); |
(...skipping 17 matching lines...) Expand all Loading... |
59 } | 72 } |
60 | 73 |
61 REGISTER_MODULE_INITIALIZER(multivalued_headers, InitMultivaluedHeaders()); | 74 REGISTER_MODULE_INITIALIZER(multivalued_headers, InitMultivaluedHeaders()); |
62 | 75 |
63 const int kFastToBufferSize = 32; // I think 22 is adequate, but anyway.. | 76 const int kFastToBufferSize = 32; // I think 22 is adequate, but anyway.. |
64 | 77 |
65 } // namespace | 78 } // namespace |
66 | 79 |
67 namespace net { | 80 namespace net { |
68 | 81 |
69 const size_t BalsaBuffer::kDefaultBlocksize; | |
70 | |
71 BalsaHeaders::iterator_base::iterator_base() : headers_(NULL), idx_(0) { } | 82 BalsaHeaders::iterator_base::iterator_base() : headers_(NULL), idx_(0) { } |
72 | 83 |
73 BalsaHeaders::iterator_base::iterator_base(const iterator_base& it) | 84 BalsaHeaders::iterator_base::iterator_base(const iterator_base& it) |
74 : headers_(it.headers_), | 85 : headers_(it.headers_), |
75 idx_(it.idx_) { | 86 idx_(it.idx_) { |
76 } | 87 } |
77 | 88 |
78 std::ostream& BalsaHeaders::iterator_base::operator<<(std::ostream& os) const { | 89 std::ostream& BalsaHeaders::iterator_base::operator<<(std::ostream& os) const { |
79 os << "[" << this->headers_ << ", " << this->idx_ << "]"; | 90 os << "[" << this->headers_ << ", " << this->idx_ << "]"; |
80 return os; | 91 return os; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 const base::StringPiece BalsaHeaders::GetHeader( | 546 const base::StringPiece BalsaHeaders::GetHeader( |
536 const base::StringPiece& key) const { | 547 const base::StringPiece& key) const { |
537 DCHECK(!IsMultivaluedHeader(key)) | 548 DCHECK(!IsMultivaluedHeader(key)) |
538 << "Header '" << key << "' may consist of multiple lines. Do not " | 549 << "Header '" << key << "' may consist of multiple lines. Do not " |
539 << "use BalsaHeaders::GetHeader() or you may be missing some of its " | 550 << "use BalsaHeaders::GetHeader() or you may be missing some of its " |
540 << "values."; | 551 << "values."; |
541 const HeaderLines::const_iterator end = header_lines_.end(); | 552 const HeaderLines::const_iterator end = header_lines_.end(); |
542 const HeaderLines::const_iterator begin = header_lines_.begin(); | 553 const HeaderLines::const_iterator begin = header_lines_.begin(); |
543 HeaderLines::const_iterator i = GetConstHeaderLinesIterator(key, begin); | 554 HeaderLines::const_iterator i = GetConstHeaderLinesIterator(key, begin); |
544 if (i == end) { | 555 if (i == end) { |
545 return base::StringPiece(NULL, 0); | 556 return base::StringPiece(); |
546 } | 557 } |
547 return GetValueFromHeaderLineDescription(*i); | 558 return GetValueFromHeaderLineDescription(*i); |
548 } | 559 } |
549 | 560 |
550 BalsaHeaders::const_header_lines_iterator BalsaHeaders::GetHeaderPosition( | 561 BalsaHeaders::const_header_lines_iterator BalsaHeaders::GetHeaderPosition( |
551 const base::StringPiece& key) const { | 562 const base::StringPiece& key) const { |
552 const HeaderLines::const_iterator end = header_lines_.end(); | 563 const HeaderLines::const_iterator end = header_lines_.end(); |
553 const HeaderLines::const_iterator begin = header_lines_.begin(); | 564 const HeaderLines::const_iterator begin = header_lines_.begin(); |
554 HeaderLines::const_iterator i = GetConstHeaderLinesIterator(key, begin); | 565 HeaderLines::const_iterator i = GetConstHeaderLinesIterator(key, begin); |
555 if (i == end) { | 566 if (i == end) { |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 965 |
955 void BalsaHeaders::SetResponseReasonPhrase(const base::StringPiece& reason) { | 966 void BalsaHeaders::SetResponseReasonPhrase(const base::StringPiece& reason) { |
956 // Note: There is no difference between request_version() and | 967 // Note: There is no difference between request_version() and |
957 // response_reason_phrase(). Thus, a function to set one is equivalent to a | 968 // response_reason_phrase(). Thus, a function to set one is equivalent to a |
958 // function to set the other. We maintain two functions for this as it is | 969 // function to set the other. We maintain two functions for this as it is |
959 // much more descriptive, and makes code more understandable. | 970 // much more descriptive, and makes code more understandable. |
960 SetRequestVersion(reason); | 971 SetRequestVersion(reason); |
961 } | 972 } |
962 | 973 |
963 } // namespace net | 974 } // namespace net |
OLD | NEW |