Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
// Qt-Security score:significant reason:default
4
5
#
ifndef
QHTTPHEADERPARSER_H
6
#
define
QHTTPHEADERPARSER_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists for the convenience
13
// of the Network Access API. This header file may change from
14
// version to version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtNetwork
/
private
/
qtnetworkglobal_p
.
h
>
20
#
include
<
QtNetwork
/
qhttpheaders
.
h
>
21
22
#
include
<
QByteArray
>
23
#
include
<
QList
>
24
#
include
<
QString
>
25
26
QT_BEGIN_NAMESPACE
27
28
namespace
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.
37
static
constexpr
qsizetype
DEFAULT_MAX_HEADER_FIELD_SIZE
= 100 * 1024;
38
// Taken from http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfields
39
static
constexpr
qsizetype
DEFAULT_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
43
static
constexpr
qsizetype
DEFAULT_MAX_TOTAL_HEADER_SIZE
= 256 * 1024;
44
// There is no strict upper limit on the phrase, but in practice it is
45
// rarely longer than 28. 1024 is quite generous, allows custom messages
46
static
constexpr
qsizetype
MAX_REASON_PHRASE_SIZE
= 1024;
47
}
48
49
class
Q_NETWORK_EXPORT
QHttpHeaderParser
50
{
51
public
:
52
QHttpHeaderParser();
53
54
void
clear();
55
bool
parseHeaders(QByteArrayView headers);
56
bool
parseStatus(QByteArrayView status);
57
58
const
QHttpHeaders& headers()
const
&;
59
QHttpHeaders headers() &&;
60
void
setStatusCode(
int
code);
61
int
getStatusCode()
const
;
62
int
getMajorVersion()
const
;
63
void
setMajorVersion(
int
version);
64
int
getMinorVersion()
const
;
65
void
setMinorVersion(
int
version);
66
QString getReasonPhrase()
const
;
67
void
setReasonPhrase(
const
QString &reason);
68
69
QByteArray firstHeaderField(QByteArrayView name,
70
const
QByteArray &defaultValue = QByteArray())
const
;
71
QByteArray combinedHeaderValue(QByteArrayView name,
72
const
QByteArray &defaultValue = QByteArray())
const
;
73
QList<QByteArray> headerFieldValues(QByteArrayView name)
const
;
74
void
setHeaderField(
const
QByteArray &name,
const
QByteArray &data);
75
void
prependHeaderField(
const
QByteArray &name,
const
QByteArray &data);
76
void
appendHeaderField(
const
QByteArray &name,
const
QByteArray &data);
77
void
removeHeaderField(QByteArrayView name);
78
void
clearHeaders();
79
80
void
setMaxHeaderFieldSize(qsizetype size) {
81
Q_ASSERT(size > 0);
82
maxFieldSize = size;
83
}
84
qsizetype maxHeaderFieldSize()
const
{
return
maxFieldSize; }
85
86
void
setMaxTotalHeaderSize(qsizetype size) {
87
Q_ASSERT(size > 0);
88
maxTotalSize = size;
89
}
90
qsizetype maxTotalHeaderSize()
const
{
return
maxTotalSize; }
91
92
qsizetype maxRawHeaderSize()
const
{
93
constexpr
qsizetype TrailingLineEndings = 4;
94
qsizetype result;
95
if
(qAddOverflow(maxTotalSize, TrailingLineEndings, &result))
96
return
(std::numeric_limits<qsizetype>::max)();
97
return
result;
98
}
99
100
void
setMaxHeaderFields(qsizetype size) {
101
Q_ASSERT(size > 0);
102
maxFieldCount = size;
103
}
104
qsizetype maxHeaderFields()
const
{
return
maxFieldCount; }
105
106
private
:
107
QHttpHeaders fields;
108
QString reasonPhrase;
109
int
statusCode;
110
int
majorVersion;
111
int
minorVersion;
112
113
qsizetype maxFieldSize = HeaderConstants::DEFAULT_MAX_HEADER_FIELD_SIZE;
114
qsizetype maxTotalSize = HeaderConstants::DEFAULT_MAX_TOTAL_HEADER_SIZE;
115
qsizetype maxFieldCount = HeaderConstants::DEFAULT_MAX_HEADER_FIELDS;
116
};
117
118
119
QT_END_NAMESPACE
120
121
#
endif
// QHTTPHEADERPARSER_H
QHttpHeaderParser
Definition
qhttpheaderparser_p.h:50
HeaderConstants
Definition
qhttpheaderparser_p.h:28
HeaderConstants::DEFAULT_MAX_HEADER_FIELDS
static constexpr qsizetype DEFAULT_MAX_HEADER_FIELDS
Definition
qhttpheaderparser_p.h:39
HeaderConstants::DEFAULT_MAX_HEADER_FIELD_SIZE
static constexpr qsizetype DEFAULT_MAX_HEADER_FIELD_SIZE
Definition
qhttpheaderparser_p.h:37
HeaderConstants::MAX_REASON_PHRASE_SIZE
static constexpr qsizetype MAX_REASON_PHRASE_SIZE
Definition
qhttpheaderparser_p.h:46
HeaderConstants::DEFAULT_MAX_TOTAL_HEADER_SIZE
static constexpr qsizetype DEFAULT_MAX_TOTAL_HEADER_SIZE
Definition
qhttpheaderparser_p.h:43
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
fieldNameCheck
static bool fieldNameCheck(QByteArrayView name)
Definition
qhttpheaderparser.cpp:27
qtbase
src
network
access
qhttpheaderparser_p.h
Generated on
for Qt by
1.18.0