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.
5 #ifndef NET_SPDY_HPACK_ENCODING_CONTEXT_H_
6 #define NET_SPDY_HPACK_ENCODING_CONTEXT_H_
12 #include "base/basictypes.h"
13 #include "base/macros.h"
14 #include "base/strings/string_piece.h"
15 #include "net/base/net_export.h"
16 #include "net/spdy/hpack_header_table.h"
18 // All section references below are to
19 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-04
24 // An encoding context is simply a header table and its associated
25 // reference set and a static table.
26 class NET_EXPORT_PRIVATE HpackEncodingContext
{
28 // The constant returned by GetTouchesAt() if the indexed entry
29 // hasn't been touched (which is distinct from having a touch count
32 // TODO(akalin): The distinction between untouched and having a
33 // touch count of 0 is confusing. Think of a better way to represent
35 static const uint32 kUntouched
;
37 HpackEncodingContext();
39 ~HpackEncodingContext();
41 uint32
GetEntryCount() const;
43 // For all accessor below, index must be < GetEntryCount().
45 // The StringPieces returned by Get{Name,Value}At() live as long as
46 // the next call to SetMaxSize() or the Process*() functions.
48 base::StringPiece
GetNameAt(uint32 index
) const;
50 base::StringPiece
GetValueAt(uint32 index
) const;
52 bool IsReferencedAt(uint32 index
) const;
54 uint32
GetTouchCountAt(uint32 index
) const;
56 void SetReferencedAt(uint32 index
, bool referenced
);
58 // Adds the given number of touches to the entry at the given
59 // index. It is guaranteed that GetTouchCountAt(index) will not
60 // equal kUntouched after this function is called (even if
62 void AddTouchesAt(uint32 index
, uint32 touch_count
);
64 // Sets the touch count of the entry at the given index to
66 void ClearTouchesAt(uint32 index
);
68 // Sets the maximum size of the encoding text, evicting entries if
70 void SetMaxSize(uint32 max_size
);
72 // The Process*() functions below return true on success and false
73 // if an error was encountered.
75 // Tries to update the encoding context given an indexed header
76 // opcode for the given index as described in 3.2.1. new_index is
77 // filled in with the index of a mutable entry, or -1 if one was not
78 // able to be created. removed_referenced_indices is filled in with
79 // the indices of all entries removed from the reference set.
80 bool ProcessIndexedHeader(uint32 index
,
82 std::vector
<uint32
>* removed_referenced_indices
);
84 // Tries to update the encoding context given a literal header with
85 // incremental indexing opcode for the given name and value as
86 // described in 3.2.1. index is filled in with the index of the new
87 // entry if the header was successfully indexed, or -1 if
88 // not. removed_referenced_indices is filled in with the indices of
89 // all entries removed from the reference set.
90 bool ProcessLiteralHeaderWithIncrementalIndexing(
91 base::StringPiece name
,
92 base::StringPiece value
,
94 std::vector
<uint32
>* removed_referenced_indices
);
97 HpackHeaderTable header_table_
;
99 DISALLOW_COPY_AND_ASSIGN(HpackEncodingContext
);
104 #endif // NET_SPDY_HPACK_ENCODING_CONTEXT_H_