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 quint32 dynamicTableCapacity() const;
43 quint32 maxDynamicTableCapacity() const;
44
45 bool encodeRequest(class BitOStream &outputStream,
46 const HttpHeader &header);
47 bool encodeResponse(BitOStream &outputStream,
48 const HttpHeader &header);
49
50 bool encodeSizeUpdate(BitOStream &outputStream,
51 quint32 newSize);
52
53 void setMaxDynamicTableSize(quint32 size);
54 void setCompressStrings(bool compress);
55
56private:
57 bool encodeRequestPseudoHeaders(BitOStream &outputStream,
58 const HttpHeader &header);
59 bool encodeHeaderField(BitOStream &outputStream,
60 const HeaderField &field);
61 bool encodeMethod(BitOStream &outputStream,
62 const HeaderField &field);
63
64 bool encodeResponsePseudoHeaders(BitOStream &outputStream,
65 const HttpHeader &header);
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
86class Q_AUTOTEST_EXPORT Decoder
87{
88public:
89 Decoder(quint32 maxTableSize);
90
91 bool decodeHeaderFields(class BitIStream &inputStream);
92
93 const HttpHeader &decodedHeader() 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
104private:
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 header;
118 FieldLookupTable lookupTable;
119};
120
121std::optional<QUrl> makePromiseKeyUrl(const HttpHeader &requestHeader);
122}
123
124QT_END_NAMESPACE
125
126#endif
127
128

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

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