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