OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/flip_server/balsa_headers.h" | 5 #include "net/tools/flip_server/balsa_headers.h" |
6 | 6 |
7 #include <emmintrin.h> | 7 #include <emmintrin.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <ext/hash_set> | |
11 #include <string> | 10 #include <string> |
12 #include <utility> | 11 #include <utility> |
13 #include <vector> | 12 #include <vector> |
14 | 13 |
| 14 #include "base/hash_tables.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/port.h" | 16 #include "base/port.h" |
17 #include "base/string_piece.h" | 17 #include "base/string_piece.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "net/tools/flip_server/balsa_enums.h" | 19 #include "net/tools/flip_server/balsa_enums.h" |
20 #include "net/tools/flip_server/buffer_interface.h" | 20 #include "net/tools/flip_server/buffer_interface.h" |
21 #include "net/tools/flip_server/simple_buffer.h" | 21 #include "net/tools/flip_server/simple_buffer.h" |
22 #include "third_party/tcmalloc/chromium/src/base/googleinit.h" | 22 #include "third_party/tcmalloc/chromium/src/base/googleinit.h" |
23 // #include "util/gtl/iterator_adaptors-inl.h" | 23 // #include "util/gtl/iterator_adaptors-inl.h" |
24 // #include "util/gtl/map-util.h" | 24 // #include "util/gtl/map-util.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const char kContentLength[] = "Content-Length"; | 28 const char kContentLength[] = "Content-Length"; |
29 const char kTransferEncoding[] = "Transfer-Encoding"; | 29 const char kTransferEncoding[] = "Transfer-Encoding"; |
30 const char kSpaceChar = ' '; | 30 const char kSpaceChar = ' '; |
31 | 31 |
32 __gnu_cxx::hash_set<base::StringPiece, | 32 base::hash_set<base::StringPiece, |
33 net::StringPieceCaseHash, | 33 net::StringPieceCaseHash, |
34 net::StringPieceCaseEqual> g_multivalued_headers; | 34 net::StringPieceCaseEqual> g_multivalued_headers; |
35 | 35 |
36 void InitMultivaluedHeaders() { | 36 void InitMultivaluedHeaders() { |
37 g_multivalued_headers.insert("accept"); | 37 g_multivalued_headers.insert("accept"); |
38 g_multivalued_headers.insert("accept-charset"); | 38 g_multivalued_headers.insert("accept-charset"); |
39 g_multivalued_headers.insert("accept-encoding"); | 39 g_multivalued_headers.insert("accept-encoding"); |
40 g_multivalued_headers.insert("accept-language"); | 40 g_multivalued_headers.insert("accept-language"); |
41 g_multivalued_headers.insert("accept-ranges"); | 41 g_multivalued_headers.insert("accept-ranges"); |
42 g_multivalued_headers.insert("allow"); | 42 g_multivalued_headers.insert("allow"); |
43 g_multivalued_headers.insert("cache-control"); | 43 g_multivalued_headers.insert("cache-control"); |
44 g_multivalued_headers.insert("connection"); | 44 g_multivalued_headers.insert("connection"); |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 } else if (transfer_encoding_is_chunked_) { | 608 } else if (transfer_encoding_is_chunked_) { |
609 const base::StringPiece transfer_encoding(kTransferEncoding, | 609 const base::StringPiece transfer_encoding(kTransferEncoding, |
610 sizeof(kTransferEncoding) - 1); | 610 sizeof(kTransferEncoding) - 1); |
611 RemoveAllOfHeader(transfer_encoding); | 611 RemoveAllOfHeader(transfer_encoding); |
612 transfer_encoding_is_chunked_ = false; | 612 transfer_encoding_is_chunked_ = false; |
613 } | 613 } |
614 content_length_status_ = BalsaHeadersEnums::VALID_CONTENT_LENGTH; | 614 content_length_status_ = BalsaHeadersEnums::VALID_CONTENT_LENGTH; |
615 content_length_ = length; | 615 content_length_ = length; |
616 // FastUInt64ToBuffer is supposed to use a maximum of kFastToBufferSize bytes. | 616 // FastUInt64ToBuffer is supposed to use a maximum of kFastToBufferSize bytes. |
617 char buffer[kFastToBufferSize]; | 617 char buffer[kFastToBufferSize]; |
618 int len_converted = snprintf(buffer, sizeof(buffer), "%d", length); | 618 int len_converted = snprintf(buffer, sizeof(buffer), "%zu", length); |
619 CHECK_GT(len_converted, 0); | 619 CHECK_GT(len_converted, 0); |
620 const base::StringPiece length_str(buffer, len_converted); | 620 const base::StringPiece length_str(buffer, len_converted); |
621 AppendHeader(content_length, length_str); | 621 AppendHeader(content_length, length_str); |
622 } | 622 } |
623 | 623 |
624 void BalsaHeaders::SetChunkEncoding(bool chunk_encode) { | 624 void BalsaHeaders::SetChunkEncoding(bool chunk_encode) { |
625 if (transfer_encoding_is_chunked_ == chunk_encode) { | 625 if (transfer_encoding_is_chunked_ == chunk_encode) { |
626 return; | 626 return; |
627 } | 627 } |
628 if (content_length_status_ != BalsaHeadersEnums::NO_CONTENT_LENGTH && | 628 if (content_length_status_ != BalsaHeadersEnums::NO_CONTENT_LENGTH && |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 // Thus, a function to set one is equivalent to a function to set the other. | 717 // Thus, a function to set one is equivalent to a function to set the other. |
718 // We maintain two functions for this as it is much more descriptive, and | 718 // We maintain two functions for this as it is much more descriptive, and |
719 // makes code more understandable. | 719 // makes code more understandable. |
720 SetRequestUri(code); | 720 SetRequestUri(code); |
721 } | 721 } |
722 | 722 |
723 void BalsaHeaders::SetParsedResponseCodeAndUpdateFirstline( | 723 void BalsaHeaders::SetParsedResponseCodeAndUpdateFirstline( |
724 size_t parsed_response_code) { | 724 size_t parsed_response_code) { |
725 char buffer[kFastToBufferSize]; | 725 char buffer[kFastToBufferSize]; |
726 int len_converted = snprintf(buffer, sizeof(buffer), | 726 int len_converted = snprintf(buffer, sizeof(buffer), |
727 "%d", parsed_response_code); | 727 "%zu", parsed_response_code); |
728 CHECK_GT(len_converted, 0); | 728 CHECK_GT(len_converted, 0); |
729 SetResponseCode(base::StringPiece(buffer, len_converted)); | 729 SetResponseCode(base::StringPiece(buffer, len_converted)); |
730 } | 730 } |
731 | 731 |
732 void BalsaHeaders::SetRequestVersion(const base::StringPiece& version) { | 732 void BalsaHeaders::SetRequestVersion(const base::StringPiece& version) { |
733 // This is the last of the three parts of the firstline. | 733 // This is the last of the three parts of the firstline. |
734 // Since whitespace_3_idx and non_whitespace_3_idx may point to the same | 734 // Since whitespace_3_idx and non_whitespace_3_idx may point to the same |
735 // place, we ensure below that any available space includes space for a | 735 // place, we ensure below that any available space includes space for a |
736 // litteral space (' ') character between the second component and the third | 736 // litteral space (' ') character between the second component and the third |
737 // component. If the space between whitespace_3_idx_ and | 737 // component. If the space between whitespace_3_idx_ and |
(...skipping 16 matching lines...) Expand all Loading... |
754 | 754 |
755 void BalsaHeaders::SetResponseReasonPhrase(const base::StringPiece& reason) { | 755 void BalsaHeaders::SetResponseReasonPhrase(const base::StringPiece& reason) { |
756 // Note: There is no difference between request_version() and | 756 // Note: There is no difference between request_version() and |
757 // response_reason_phrase(). Thus, a function to set one is equivalent to a | 757 // response_reason_phrase(). Thus, a function to set one is equivalent to a |
758 // function to set the other. We maintain two functions for this as it is | 758 // function to set the other. We maintain two functions for this as it is |
759 // much more descriptive, and makes code more understandable. | 759 // much more descriptive, and makes code more understandable. |
760 SetRequestVersion(reason); | 760 SetRequestVersion(reason); |
761 } | 761 } |
762 | 762 |
763 } // namespace net | 763 } // namespace net |
OLD | NEW |