Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qhttpheaderparser_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QHTTPHEADERPARSER_H
5#define QHTTPHEADERPARSER_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 the Network Access API. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/private/qtnetworkglobal_p.h>
19#include <QtNetwork/qhttpheaders.h>
20
21#include <QByteArray>
22#include <QList>
23#include <QPair>
24#include <QString>
25
27
28namespace HeaderConstants {
29
30// We previously used 8K, which is common on server side, but it turned out to
31// not be enough for various uses. Historically Firefox used 10K as the limit of
32// a single field, but some Location headers and Authorization challenges can
33// get even longer. Other browsers, such as Chrome, instead have a limit on the
34// total size of all the headers (as well as extra limits on some of the
35// individual fields). We'll use 100K as our default limit, which would be a ridiculously large
36// header, with the possibility to override it where we need to.
37static constexpr int MAX_HEADER_FIELD_SIZE = 100 * 1024;
38// Taken from http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfields
39static constexpr int MAX_HEADER_FIELDS = 100;
40// Chromium has a limit on the total size of the header set to 256KB,
41// which is a reasonable default for QNetworkAccessManager.
42// https://stackoverflow.com/a/3436155
43static constexpr int MAX_TOTAL_HEADER_SIZE = 256 * 1024;
44
45}
46
47class Q_NETWORK_EXPORT QHttpHeaderParser
48{
49public:
51
52 void clear();
53 bool parseHeaders(QByteArrayView headers);
54 bool parseStatus(QByteArrayView status);
55
56 const QHttpHeaders& headers() const;
57 void setStatusCode(int code);
58 int getStatusCode() const;
59 int getMajorVersion() const;
60 void setMajorVersion(int version);
61 int getMinorVersion() const;
62 void setMinorVersion(int version);
63 QString getReasonPhrase() const;
64 void setReasonPhrase(const QString &reason);
65
66 QByteArray firstHeaderField(QByteArrayView name,
67 const QByteArray &defaultValue = QByteArray()) const;
68 QByteArray combinedHeaderValue(QByteArrayView name,
69 const QByteArray &defaultValue = QByteArray()) const;
70 QList<QByteArray> headerFieldValues(QByteArrayView name) const;
71 void setHeaderField(const QByteArray &name, const QByteArray &data);
72 void prependHeaderField(const QByteArray &name, const QByteArray &data);
73 void appendHeaderField(const QByteArray &name, const QByteArray &data);
74 void removeHeaderField(QByteArrayView name);
75 void clearHeaders();
76
77 void setMaxHeaderFieldSize(qsizetype size) { maxFieldSize = size; }
78 qsizetype maxHeaderFieldSize() const { return maxFieldSize; }
79
80 void setMaxTotalHeaderSize(qsizetype size) { maxTotalSize = size; }
81 qsizetype maxTotalHeaderSize() const { return maxTotalSize; }
82
83 void setMaxHeaderFields(qsizetype count) { maxFieldCount = count; }
84 qsizetype maxHeaderFields() const { return maxFieldCount; }
85
86private:
87 QHttpHeaders fields;
88 QString reasonPhrase;
89 int statusCode;
90 int majorVersion;
91 int minorVersion;
92
96};
97
98
100
101#endif // QHTTPHEADERPARSER_H
\inmodule QtCore
Definition qbytearray.h:57
qsizetype maxHeaderFieldSize() const
void setMaxTotalHeaderSize(qsizetype size)
qsizetype maxHeaderFields() const
void setMaxHeaderFields(qsizetype count)
qsizetype maxTotalHeaderSize() const
void setMaxHeaderFieldSize(qsizetype size)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
b clear()
static constexpr int MAX_HEADER_FIELD_SIZE
static constexpr int MAX_TOTAL_HEADER_SIZE
static constexpr int MAX_HEADER_FIELDS
Combined button and popup list for selecting options.
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
ptrdiff_t qsizetype
Definition qtypes.h:165