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
6
7#include <algorithm>
8
9QT_BEGIN_NAMESPACE
10
11QHttpNetworkHeader::~QHttpNetworkHeader()
12 = default;
13
14QHttpNetworkHeaderPrivate::QHttpNetworkHeaderPrivate(const QUrl &newUrl)
15 :url(newUrl)
16{
17}
18
19qint64 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
31void QHttpNetworkHeaderPrivate::setContentLength(qint64 length)
32{
33 setHeaderField("Content-Length", QByteArray::number(length));
34}
35
36QByteArray 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
45QList<QByteArray> QHttpNetworkHeaderPrivate::headerFieldValues(QByteArrayView name) const
46{
47 return parser.headerFieldValues(name);
48}
49
50void QHttpNetworkHeaderPrivate::setHeaderField(const QByteArray &name, const QByteArray &data)
51{
52 parser.setHeaderField(name, data);
53}
54
55void QHttpNetworkHeaderPrivate::prependHeaderField(const QByteArray &name, const QByteArray &data)
56{
57 parser.prependHeaderField(name, data);
58}
59
60QHttpHeaders QHttpNetworkHeaderPrivate::headers() const
61{
62 return parser.headers();
63}
64
65void QHttpNetworkHeaderPrivate::clearHeaders()
66{
67 parser.clearHeaders();
68}
69
70bool QHttpNetworkHeaderPrivate::operator==(const QHttpNetworkHeaderPrivate &other) const
71{
72 return (url == other.url);
73}
74
75
76QT_END_NAMESPACE