| 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_DECODER_H_ | 5 #ifndef NET_SPDY_HPACK_DECODER_H_ |
| 6 #define NET_SPDY_HPACK_DECODER_H_ | 6 #define NET_SPDY_HPACK_DECODER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
| 16 #include "net/spdy/hpack_encoding_context.h" | 16 #include "net/spdy/hpack_header_table.h" |
| 17 #include "net/spdy/hpack_input_stream.h" | 17 #include "net/spdy/hpack_input_stream.h" |
| 18 #include "net/spdy/spdy_protocol.h" | 18 #include "net/spdy/spdy_protocol.h" |
| 19 | 19 |
| 20 // An HpackDecoder decodes header sets as outlined in | 20 // An HpackDecoder decodes header sets as outlined in |
| 21 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06 | 21 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06 |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 | 24 |
| 25 class HpackHuffmanTable; | 25 class HpackHuffmanTable; |
| 26 | 26 |
| 27 namespace test { | 27 namespace test { |
| 28 class HpackDecoderPeer; | 28 class HpackDecoderPeer; |
| 29 } // namespace test | 29 } // namespace test |
| 30 | 30 |
| 31 class NET_EXPORT_PRIVATE HpackDecoder { | 31 class NET_EXPORT_PRIVATE HpackDecoder { |
| 32 public: | 32 public: |
| 33 friend class test::HpackDecoderPeer; | 33 friend class test::HpackDecoderPeer; |
| 34 | 34 |
| 35 // |table| is an initialized HPACK Huffman table, having an | 35 // |table| is an initialized HPACK Huffman table, having an |
| 36 // externally-managed lifetime which spans beyond HpackDecoder. | 36 // externally-managed lifetime which spans beyond HpackDecoder. |
| 37 explicit HpackDecoder(const HpackHuffmanTable& table); | 37 explicit HpackDecoder(const HpackHuffmanTable& table); |
| 38 ~HpackDecoder(); | 38 ~HpackDecoder(); |
| 39 | 39 |
| 40 // Called upon acknowledgement of SETTINGS_HEADER_TABLE_SIZE. | 40 // Called upon acknowledgement of SETTINGS_HEADER_TABLE_SIZE. |
| 41 // See HpackEncodingContext::ApplyHeaderTableSizeSetting(). | 41 void ApplyHeaderTableSizeSetting(size_t size_setting) { |
| 42 void ApplyHeaderTableSizeSetting(uint32 max_size); | 42 header_table_.SetSettingsHeaderTableSize(size_setting); |
| 43 } |
| 43 | 44 |
| 44 // Called as headers data arrives. Returns false if an error occurred. | 45 // Called as headers data arrives. Returns false if an error occurred. |
| 45 // TODO(jgraettinger): A future version of this method will incrementally | 46 // TODO(jgraettinger): A future version of this method will incrementally |
| 46 // parse and deliver headers via SpdyHeadersHandlerInterface. For now, | 47 // parse and deliver headers via SpdyHeadersHandlerInterface. For now, |
| 47 // header data is buffered until HandleControlFrameHeadersComplete(). | 48 // header data is buffered until HandleControlFrameHeadersComplete(). |
| 48 bool HandleControlFrameHeadersData(SpdyStreamId stream_id, | 49 bool HandleControlFrameHeadersData(SpdyStreamId stream_id, |
| 49 const char* headers_data, | 50 const char* headers_data, |
| 50 size_t headers_data_length); | 51 size_t headers_data_length); |
| 51 | 52 |
| 52 // Called after a headers block has been completely delivered via | 53 // Called after a headers block has been completely delivered via |
| (...skipping 22 matching lines...) Expand all Loading... |
| 75 // - Multiple values of other headers are joined and delimited by '\0'. | 76 // - Multiple values of other headers are joined and delimited by '\0'. |
| 76 // Note that this may be too accomodating, as the sender's HTTP2 layer | 77 // Note that this may be too accomodating, as the sender's HTTP2 layer |
| 77 // should have already joined and delimited these values. | 78 // should have already joined and delimited these values. |
| 78 // | 79 // |
| 79 // TODO(jgraettinger): This method will eventually emit to the | 80 // TODO(jgraettinger): This method will eventually emit to the |
| 80 // SpdyHeadersHandlerInterface visitor. | 81 // SpdyHeadersHandlerInterface visitor. |
| 81 void HandleHeaderRepresentation(base::StringPiece name, | 82 void HandleHeaderRepresentation(base::StringPiece name, |
| 82 base::StringPiece value); | 83 base::StringPiece value); |
| 83 | 84 |
| 84 const uint32 max_string_literal_size_; | 85 const uint32 max_string_literal_size_; |
| 85 HpackEncodingContext context_; | 86 HpackHeaderTable header_table_; |
| 86 | 87 |
| 87 // Incrementally reconstructed cookie value. Name is also kept to preserve | 88 // Incrementally reconstructed cookie value. Name is also kept to preserve |
| 88 // input casing. | 89 // input casing. |
| 89 std::string cookie_value_, cookie_name_; | 90 std::string cookie_value_, cookie_name_; |
| 90 | 91 |
| 91 // TODO(jgraettinger): Buffer for headers data, and storage for the last- | 92 // TODO(jgraettinger): Buffer for headers data, and storage for the last- |
| 92 // processed headers block. Both will be removed with the switch to | 93 // processed headers block. Both will be removed with the switch to |
| 93 // SpdyHeadersHandlerInterface. | 94 // SpdyHeadersHandlerInterface. |
| 94 std::string headers_block_buffer_; | 95 std::string headers_block_buffer_; |
| 95 std::map<std::string, std::string> decoded_block_; | 96 std::map<std::string, std::string> decoded_block_; |
| 96 | 97 |
| 97 // Huffman table to be applied to decoded Huffman literals, | 98 // Huffman table to be applied to decoded Huffman literals, |
| 98 // and scratch space for storing those decoded literals. | 99 // and scratch space for storing those decoded literals. |
| 99 const HpackHuffmanTable& huffman_table_; | 100 const HpackHuffmanTable& huffman_table_; |
| 100 std::string huffman_key_buffer_, huffman_value_buffer_; | 101 std::string key_buffer_, value_buffer_; |
| 101 | 102 |
| 102 // Handlers for decoding HPACK opcodes and header representations | 103 // Handlers for decoding HPACK opcodes and header representations |
| 103 // (or parts thereof). These methods return true on success and | 104 // (or parts thereof). These methods return true on success and |
| 104 // false on error. | 105 // false on error. |
| 105 bool DecodeNextOpcode(HpackInputStream* input_stream); | 106 bool DecodeNextOpcode(HpackInputStream* input_stream); |
| 106 bool DecodeNextContextUpdate(HpackInputStream* input_stream); | 107 bool DecodeNextContextUpdate(HpackInputStream* input_stream); |
| 107 bool DecodeNextIndexedHeader(HpackInputStream* input_stream); | 108 bool DecodeNextIndexedHeader(HpackInputStream* input_stream); |
| 108 bool DecodeNextLiteralHeader(HpackInputStream* input_stream, | 109 bool DecodeNextLiteralHeader(HpackInputStream* input_stream, |
| 109 bool should_index); | 110 bool should_index); |
| 110 bool DecodeNextName(HpackInputStream* input_stream, | 111 bool DecodeNextName(HpackInputStream* input_stream, |
| 111 base::StringPiece* next_name); | 112 base::StringPiece* next_name); |
| 112 bool DecodeNextStringLiteral(HpackInputStream* input_stream, | 113 bool DecodeNextStringLiteral(HpackInputStream* input_stream, |
| 113 bool is_header_key, // As distinct from a value. | 114 bool is_header_key, // As distinct from a value. |
| 114 base::StringPiece* output); | 115 base::StringPiece* output); |
| 115 | 116 |
| 116 DISALLOW_COPY_AND_ASSIGN(HpackDecoder); | 117 DISALLOW_COPY_AND_ASSIGN(HpackDecoder); |
| 117 }; | 118 }; |
| 118 | 119 |
| 119 } // namespace net | 120 } // namespace net |
| 120 | 121 |
| 121 #endif // NET_SPDY_HPACK_DECODER_H_ | 122 #endif // NET_SPDY_HPACK_DECODER_H_ |
| OLD | NEW |