1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef HPACK_P_H
5#define HPACK_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "hpacktable_p.h"
19
20#include <QtCore/qglobal.h>
21
22#include <vector>
23
24QT_BEGIN_NAMESPACE
25
26class QByteArray;
27
28namespace HPack
29{
30
31using HttpHeader = std::vector<HeaderField>;
32HeaderSize header_size(const HttpHeader &header);
33
34class Q_AUTOTEST_EXPORT Encoder
35{
36public:
37 Encoder(quint32 maxTableSize, bool compressStrings);
38
39 quint32 dynamicTableSize() const;
40
41 bool encodeRequest(class BitOStream &outputStream,
42 const HttpHeader &header);
43 bool encodeResponse(BitOStream &outputStream,
44 const HttpHeader &header);
45
46 bool encodeSizeUpdate(BitOStream &outputStream,
47 quint32 newSize);
48
49 void setMaxDynamicTableSize(quint32 size);
50 void setCompressStrings(bool compress);
51
52private:
53 bool encodeRequestPseudoHeaders(BitOStream &outputStream,
54 const HttpHeader &header);
55 bool encodeHeaderField(BitOStream &outputStream,
56 const HeaderField &field);
57 bool encodeMethod(BitOStream &outputStream,
58 const HeaderField &field);
59
60 bool encodeResponsePseudoHeaders(BitOStream &outputStream,
61 const HttpHeader &header);
62
63 bool encodeIndexedField(BitOStream &outputStream, quint32 index) const;
64
65
66 bool encodeLiteralField(BitOStream &outputStream,
67 const struct BitPattern &fieldType,
68 quint32 nameIndex,
69 const QByteArray &value,
70 bool withCompression);
71
72 bool encodeLiteralField(BitOStream &outputStream,
73 const BitPattern &fieldType,
74 const QByteArray &name,
75 const QByteArray &value,
76 bool withCompression);
77
78 FieldLookupTable lookupTable;
79 bool compressStrings;
80};
81
82class Q_AUTOTEST_EXPORT Decoder
83{
84public:
85 Decoder(quint32 maxTableSize);
86
87 bool decodeHeaderFields(class BitIStream &inputStream);
88
89 const HttpHeader &decodedHeader() const
90 {
91 return header;
92 }
93
94 quint32 dynamicTableSize() const;
95
96 void setMaxDynamicTableSize(quint32 size);
97
98private:
99
100 bool decodeIndexedField(BitIStream &inputStream);
101 bool decodeSizeUpdate(BitIStream &inputStream);
102 bool decodeLiteralField(const BitPattern &fieldType,
103 BitIStream &inputStream);
104
105 bool processDecodedField(const BitPattern &fieldType,
106 const QByteArray &name,
107 const QByteArray &value);
108
109 void handleStreamError(BitIStream &inputStream);
110
111 HttpHeader header;
112 FieldLookupTable lookupTable;
113};
114
115}
116
117QT_END_NAMESPACE
118
119#endif
120
121

source code of qtbase/src/network/access/http2/hpack_p.h