Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / net / spdy / hpack_decoder.h
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
3 // found in the LICENSE file.
4
5 #ifndef NET_SPDY_HPACK_DECODER_H_
6 #define NET_SPDY_HPACK_DECODER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/macros.h"
13 #include "base/strings/string_piece.h"
14 #include "net/base/net_export.h"
15 #include "net/spdy/hpack_encoding_context.h"
16 #include "net/spdy/hpack_input_stream.h"  // For HpackHeaderPairVector.
17
18 namespace net {
19
20 // An HpackDecoder decodes header sets as outlined in
21 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-05
22 // .
23 class NET_EXPORT_PRIVATE HpackDecoder {
24  public:
25   explicit HpackDecoder(uint32 max_string_literal_size);
26   ~HpackDecoder();
27
28   // Decodes the given string into the given header set. Returns
29   // whether or not the decoding was successful.
30   //
31   // TODO(akalin): Emit the headers via a callback/delegate instead of
32   // putting them into a vector.
33   bool DecodeHeaderSet(base::StringPiece input,
34                        HpackHeaderPairVector* header_list);
35
36   // Accessors for testing.
37
38   bool DecodeNextNameForTest(HpackInputStream* input_stream,
39                              base::StringPiece* next_name) {
40     return DecodeNextName(input_stream, next_name);
41   }
42
43  private:
44   const uint32 max_string_literal_size_;
45   HpackEncodingContext context_;
46
47   // Tries to process the next header representation and maybe emit
48   // headers into |header_list| according to it. Returns true if
49   // successful, or false if an error was encountered.
50   bool ProcessNextHeaderRepresentation(
51       HpackInputStream* input_stream,
52       HpackHeaderPairVector* header_list);
53
54   bool DecodeNextName(HpackInputStream* input_stream,
55                       base::StringPiece* next_name);
56   bool DecodeNextValue(HpackInputStream* input_stream,
57                        base::StringPiece* next_name);
58
59   DISALLOW_COPY_AND_ASSIGN(HpackDecoder);
60 };
61
62 }  // namespace net
63
64 #endif  // NET_SPDY_HPACK_DECODER_H_