Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qhttpnetworkheader.cpp
Go to the documentation of this file.
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
// Qt-Security score:significant reason:default
4
5
#
include
"qhttpnetworkheader_p.h"
6
7
#
include
<
algorithm
>
8
9
QT_BEGIN_NAMESPACE
10
11
QHttpNetworkHeader::~QHttpNetworkHeader()
12
=
default
;
13
14
QHttpNetworkHeaderPrivate::QHttpNetworkHeaderPrivate(
const
QUrl &newUrl)
15
:url(newUrl)
16
{
17
}
18
19
qint64 QHttpNetworkHeaderPrivate::contentLength()
const
20
{
21
bool
ok =
false
;
22
// We are not using the headerField() method here because servers might send us multiple content-length
23
// headers which is crap (see QTBUG-15311). Therefore just take the first content-length header field.
24
QByteArray value = parser.firstHeaderField(
"content-length"
);
25
qint64 length = value.toULongLong(&ok);
26
if
(ok)
27
return
length;
28
return
-1;
// the header field is not set
29
}
30
31
void
QHttpNetworkHeaderPrivate::setContentLength(qint64 length)
32
{
33
setHeaderField(
"Content-Length"
, QByteArray::number(length));
34
}
35
36
QByteArray QHttpNetworkHeaderPrivate::headerField(QByteArrayView name,
const
QByteArray &defaultValue)
const
37
{
38
QList<QByteArray> allValues = headerFieldValues(name);
39
if
(allValues.isEmpty())
40
return
defaultValue;
41
else
42
return
allValues.join(
", "
);
43
}
44
45
QList<QByteArray> QHttpNetworkHeaderPrivate::headerFieldValues(QByteArrayView name)
const
46
{
47
return
parser.headerFieldValues(name);
48
}
49
50
void
QHttpNetworkHeaderPrivate::setHeaderField(
const
QByteArray &name,
const
QByteArray &data)
51
{
52
parser.setHeaderField(name, data);
53
}
54
55
void
QHttpNetworkHeaderPrivate::prependHeaderField(
const
QByteArray &name,
const
QByteArray &data)
56
{
57
parser.prependHeaderField(name, data);
58
}
59
60
QHttpHeaders QHttpNetworkHeaderPrivate::headers()
const
61
{
62
return
parser.headers();
63
}
64
65
void
QHttpNetworkHeaderPrivate::clearHeaders()
66
{
67
parser.clearHeaders();
68
}
69
70
bool
QHttpNetworkHeaderPrivate::operator==(
const
QHttpNetworkHeaderPrivate &other)
const
71
{
72
return
(url == other.url);
73
}
74
75
76
QT_END_NAMESPACE
qtbase
src
network
access
qhttpnetworkheader.cpp
Generated on
for Qt by
1.14.0