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 | |
43 | bool (class BitOStream &outputStream, |
44 | const HttpHeader &); |
45 | bool (BitOStream &outputStream, |
46 | const HttpHeader &); |
47 | |
48 | bool encodeSizeUpdate(BitOStream &outputStream, |
49 | quint32 newSize); |
50 | |
51 | void setMaxDynamicTableSize(quint32 size); |
52 | void setCompressStrings(bool compress); |
53 | |
54 | private: |
55 | bool (BitOStream &outputStream, |
56 | const HttpHeader &); |
57 | bool (BitOStream &outputStream, |
58 | const HeaderField &field); |
59 | bool (BitOStream &outputStream, |
60 | const HeaderField &field); |
61 | |
62 | bool (BitOStream &outputStream, |
63 | const HttpHeader &); |
64 | |
65 | bool encodeIndexedField(BitOStream &outputStream, quint32 index) const; |
66 | |
67 | |
68 | bool encodeLiteralField(BitOStream &outputStream, |
69 | BitPattern fieldType, |
70 | quint32 nameIndex, |
71 | const QByteArray &value, |
72 | bool withCompression); |
73 | |
74 | bool encodeLiteralField(BitOStream &outputStream, |
75 | BitPattern fieldType, |
76 | const QByteArray &name, |
77 | const QByteArray &value, |
78 | bool withCompression); |
79 | |
80 | FieldLookupTable lookupTable; |
81 | bool compressStrings; |
82 | }; |
83 | |
84 | class Q_AUTOTEST_EXPORT Decoder |
85 | { |
86 | public: |
87 | Decoder(quint32 maxTableSize); |
88 | |
89 | bool (class BitIStream &inputStream); |
90 | |
91 | const HttpHeader &() const |
92 | { |
93 | return header; |
94 | } |
95 | |
96 | quint32 dynamicTableSize() const; |
97 | |
98 | void setMaxDynamicTableSize(quint32 size); |
99 | |
100 | private: |
101 | |
102 | bool decodeIndexedField(BitIStream &inputStream); |
103 | bool decodeSizeUpdate(BitIStream &inputStream); |
104 | bool decodeLiteralField(BitPattern fieldType, |
105 | BitIStream &inputStream); |
106 | |
107 | bool processDecodedField(BitPattern fieldType, |
108 | const QByteArray &name, |
109 | const QByteArray &value); |
110 | |
111 | void handleStreamError(BitIStream &inputStream); |
112 | |
113 | HttpHeader ; |
114 | FieldLookupTable lookupTable; |
115 | }; |
116 | |
117 | std::optional<QUrl> (const HttpHeader &); |
118 | } |
119 | |
120 | QT_END_NAMESPACE |
121 | |
122 | #endif |
123 | |
124 | |