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 | #include <QtCore/qurl.h> |
22 | |
23 | #include <vector> |
24 | #include <optional> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QByteArray; |
29 | |
30 | namespace HPack |
31 | { |
32 | |
33 | using = std::vector<HeaderField>; |
34 | HeaderSize (const HttpHeader &); |
35 | struct BitPattern; |
36 | class Q_AUTOTEST_EXPORT Encoder |
37 | { |
38 | public: |
39 | Encoder(quint32 maxTableSize, bool compressStrings); |
40 | |
41 | quint32 dynamicTableSize() const; |
42 | quint32 dynamicTableCapacity() const; |
43 | quint32 maxDynamicTableCapacity() const; |
44 | |
45 | bool (class BitOStream &outputStream, |
46 | const HttpHeader &); |
47 | bool (BitOStream &outputStream, |
48 | const HttpHeader &); |
49 | |
50 | bool encodeSizeUpdate(BitOStream &outputStream, |
51 | quint32 newSize); |
52 | |
53 | void setMaxDynamicTableSize(quint32 size); |
54 | void setCompressStrings(bool compress); |
55 | |
56 | private: |
57 | bool (BitOStream &outputStream, |
58 | const HttpHeader &); |
59 | bool (BitOStream &outputStream, |
60 | const HeaderField &field); |
61 | bool (BitOStream &outputStream, |
62 | const HeaderField &field); |
63 | |
64 | bool (BitOStream &outputStream, |
65 | const HttpHeader &); |
66 | |
67 | bool encodeIndexedField(BitOStream &outputStream, quint32 index) const; |
68 | |
69 | |
70 | bool encodeLiteralField(BitOStream &outputStream, |
71 | BitPattern fieldType, |
72 | quint32 nameIndex, |
73 | const QByteArray &value, |
74 | bool withCompression); |
75 | |
76 | bool encodeLiteralField(BitOStream &outputStream, |
77 | BitPattern fieldType, |
78 | const QByteArray &name, |
79 | const QByteArray &value, |
80 | bool withCompression); |
81 | |
82 | FieldLookupTable lookupTable; |
83 | bool compressStrings; |
84 | }; |
85 | |
86 | class Q_AUTOTEST_EXPORT Decoder |
87 | { |
88 | public: |
89 | Decoder(quint32 maxTableSize); |
90 | |
91 | bool (class BitIStream &inputStream); |
92 | |
93 | const HttpHeader &() const |
94 | { |
95 | return header; |
96 | } |
97 | |
98 | quint32 dynamicTableSize() const; |
99 | quint32 dynamicTableCapacity() const; |
100 | quint32 maxDynamicTableCapacity() const; |
101 | |
102 | void setMaxDynamicTableSize(quint32 size); |
103 | |
104 | private: |
105 | |
106 | bool decodeIndexedField(BitIStream &inputStream); |
107 | bool decodeSizeUpdate(BitIStream &inputStream); |
108 | bool decodeLiteralField(BitPattern fieldType, |
109 | BitIStream &inputStream); |
110 | |
111 | bool processDecodedField(BitPattern fieldType, |
112 | const QByteArray &name, |
113 | const QByteArray &value); |
114 | |
115 | void handleStreamError(BitIStream &inputStream); |
116 | |
117 | HttpHeader ; |
118 | FieldLookupTable lookupTable; |
119 | }; |
120 | |
121 | std::optional<QUrl> (const HttpHeader &); |
122 | } |
123 | |
124 | QT_END_NAMESPACE |
125 | |
126 | #endif |
127 | |
128 | |