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
26QT_BEGIN_NAMESPACE
27
28class QByteArray;
29
30namespace HPack
31{
32
33using HttpHeader = std::vector<HeaderField>;
34HeaderSize header_size(const HttpHeader &header);
35struct BitPattern;
36class Q_AUTOTEST_EXPORT Encoder
37{
38public:
39 Encoder(quint32 maxTableSize, bool compressStrings);
40
41 quint32 dynamicTableSize() const;
42
43 bool encodeRequest(class BitOStream &outputStream,
44 const HttpHeader &header);
45 bool encodeResponse(BitOStream &outputStream,
46 const HttpHeader &header);
47
48 bool encodeSizeUpdate(BitOStream &outputStream,
49 quint32 newSize);
50
51 void setMaxDynamicTableSize(quint32 size);
52 void setCompressStrings(bool compress);
53
54private:
55 bool encodeRequestPseudoHeaders(BitOStream &outputStream,
56 const HttpHeader &header);
57 bool encodeHeaderField(BitOStream &outputStream,
58 const HeaderField &field);
59 bool encodeMethod(BitOStream &outputStream,
60 const HeaderField &field);
61
62 bool encodeResponsePseudoHeaders(BitOStream &outputStream,
63 const HttpHeader &header);
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
84class Q_AUTOTEST_EXPORT Decoder
85{
86public:
87 Decoder(quint32 maxTableSize);
88
89 bool decodeHeaderFields(class BitIStream &inputStream);
90
91 const HttpHeader &decodedHeader() const
92 {
93 return header;
94 }
95
96 quint32 dynamicTableSize() const;
97
98 void setMaxDynamicTableSize(quint32 size);
99
100private:
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 header;
114 FieldLookupTable lookupTable;
115};
116
117std::optional<QUrl> makePromiseKeyUrl(const HttpHeader &requestHeader);
118}
119
120QT_END_NAMESPACE
121
122#endif
123
124

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

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