OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef NET_SPDY_HPACK_HPACK_ENCODER_H_ | 5 #ifndef NET_SPDY_HPACK_HPACK_ENCODER_H_ |
6 #define NET_SPDY_HPACK_HPACK_ENCODER_H_ | 6 #define NET_SPDY_HPACK_HPACK_ENCODER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
18 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
19 #include "net/spdy/hpack/hpack_header_table.h" | 19 #include "net/spdy/hpack/hpack_header_table.h" |
20 #include "net/spdy/hpack/hpack_output_stream.h" | 20 #include "net/spdy/hpack/hpack_output_stream.h" |
21 #include "net/spdy/spdy_protocol.h" | 21 #include "net/spdy/spdy_protocol.h" |
22 | 22 |
23 using base::StringPiece; | |
Bence
2016/08/15 13:58:31
Please remove this using directive. Unfortunately
| |
24 | |
23 // An HpackEncoder encodes header sets as outlined in | 25 // An HpackEncoder encodes header sets as outlined in |
24 // http://tools.ietf.org/html/rfc7541. | 26 // http://tools.ietf.org/html/rfc7541. |
25 | 27 |
26 namespace net { | 28 namespace net { |
27 | 29 |
28 class HpackHuffmanTable; | 30 class HpackHuffmanTable; |
29 | 31 |
30 namespace test { | 32 namespace test { |
31 class HpackEncoderPeer; | 33 class HpackEncoderPeer; |
32 } // namespace test | 34 } // namespace test |
33 | 35 |
34 class NET_EXPORT_PRIVATE HpackEncoder { | 36 class NET_EXPORT_PRIVATE HpackEncoder { |
35 public: | 37 public: |
36 using Representation = std::pair<base::StringPiece, base::StringPiece>; | 38 using Representation = std::pair<base::StringPiece, base::StringPiece>; |
37 using Representations = std::vector<Representation>; | 39 using Representations = std::vector<Representation>; |
38 | 40 |
41 // Callers may provide a HeaderListener to be informed of header name-value | |
42 // pairs processed by this encoder. | |
43 typedef std::function<void(StringPiece, StringPiece)> HeaderListener; | |
44 | |
39 // An indexing policy should return true if the provided header name-value | 45 // An indexing policy should return true if the provided header name-value |
40 // pair should be inserted into the HPACK dynamic table. | 46 // pair should be inserted into the HPACK dynamic table. |
41 using IndexingPolicy = | 47 using IndexingPolicy = |
42 std::function<bool(base::StringPiece, base::StringPiece)>; | 48 std::function<bool(base::StringPiece, base::StringPiece)>; |
43 | 49 |
44 // |table| is an initialized HPACK Huffman table, having an | 50 // |table| is an initialized HPACK Huffman table, having an |
45 // externally-managed lifetime which spans beyond HpackEncoder. | 51 // externally-managed lifetime which spans beyond HpackEncoder. |
46 explicit HpackEncoder(const HpackHuffmanTable& table); | 52 explicit HpackEncoder(const HpackHuffmanTable& table); |
47 ~HpackEncoder(); | 53 ~HpackEncoder(); |
48 | 54 |
(...skipping 17 matching lines...) Expand all Loading... | |
66 void ApplyHeaderTableSizeSetting(size_t size_setting); | 72 void ApplyHeaderTableSizeSetting(size_t size_setting); |
67 | 73 |
68 size_t CurrentHeaderTableSizeSetting() const { | 74 size_t CurrentHeaderTableSizeSetting() const { |
69 return header_table_.settings_size_bound(); | 75 return header_table_.settings_size_bound(); |
70 } | 76 } |
71 | 77 |
72 // This HpackEncoder will use |policy| to determine whether to insert header | 78 // This HpackEncoder will use |policy| to determine whether to insert header |
73 // name-value pairs into the dynamic table. | 79 // name-value pairs into the dynamic table. |
74 void SetIndexingPolicy(IndexingPolicy policy) { should_index_ = policy; } | 80 void SetIndexingPolicy(IndexingPolicy policy) { should_index_ = policy; } |
75 | 81 |
82 // |listener| will be invoked for each header name-value pair processed by | |
83 // this encoder. | |
84 void SetHeaderListener(HeaderListener listener) { listener_ = listener; } | |
85 | |
76 void SetHeaderTableDebugVisitor( | 86 void SetHeaderTableDebugVisitor( |
77 std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor) { | 87 std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor) { |
78 header_table_.set_debug_visitor(std::move(visitor)); | 88 header_table_.set_debug_visitor(std::move(visitor)); |
79 } | 89 } |
80 | 90 |
81 private: | 91 private: |
82 friend class test::HpackEncoderPeer; | 92 friend class test::HpackEncoderPeer; |
83 | 93 |
84 class RepresentationIterator; | 94 class RepresentationIterator; |
85 | 95 |
(...skipping 21 matching lines...) Expand all Loading... | |
107 | 117 |
108 // Crumbles other header field values at \0 delimiters. | 118 // Crumbles other header field values at \0 delimiters. |
109 static void DecomposeRepresentation(const Representation& header_field, | 119 static void DecomposeRepresentation(const Representation& header_field, |
110 Representations* out); | 120 Representations* out); |
111 | 121 |
112 HpackHeaderTable header_table_; | 122 HpackHeaderTable header_table_; |
113 HpackOutputStream output_stream_; | 123 HpackOutputStream output_stream_; |
114 | 124 |
115 const HpackHuffmanTable& huffman_table_; | 125 const HpackHuffmanTable& huffman_table_; |
116 size_t min_table_size_setting_received_; | 126 size_t min_table_size_setting_received_; |
127 HeaderListener listener_; | |
117 IndexingPolicy should_index_; | 128 IndexingPolicy should_index_; |
118 bool allow_huffman_compression_; | 129 bool allow_huffman_compression_; |
119 bool should_emit_table_size_; | 130 bool should_emit_table_size_; |
120 | 131 |
121 DISALLOW_COPY_AND_ASSIGN(HpackEncoder); | 132 DISALLOW_COPY_AND_ASSIGN(HpackEncoder); |
122 }; | 133 }; |
123 | 134 |
124 } // namespace net | 135 } // namespace net |
125 | 136 |
126 #endif // NET_SPDY_HPACK_HPACK_ENCODER_H_ | 137 #endif // NET_SPDY_HPACK_HPACK_ENCODER_H_ |
OLD | NEW |