diff options
Diffstat (limited to 'src/network/access/qhttpnetworkreply.cpp')
-rw-r--r-- | src/network/access/qhttpnetworkreply.cpp | 103 |
1 files changed, 27 insertions, 76 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 7582ce179f..5711c96b18 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qhttpnetworkreply_p.h" #include "qhttpnetworkconnection_p.h" @@ -50,6 +14,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QHttpNetworkReply::QHttpNetworkReply(const QUrl &url, QObject *parent) : QObject(*new QHttpNetworkReplyPrivate(url), parent) { @@ -101,12 +67,12 @@ void QHttpNetworkReply::setContentLength(qint64 length) d->setContentLength(length); } -QList<QPair<QByteArray, QByteArray> > QHttpNetworkReply::header() const +QHttpHeaders QHttpNetworkReply::header() const { return d_func()->parser.headers(); } -QByteArray QHttpNetworkReply::headerField(const QByteArray &name, const QByteArray &defaultValue) const +QByteArray QHttpNetworkReply::headerField(QByteArrayView name, const QByteArray &defaultValue) const { return d_func()->headerField(name, defaultValue); } @@ -123,7 +89,7 @@ void QHttpNetworkReply::appendHeaderField(const QByteArray &name, const QByteArr d->appendHeaderField(name, data); } -void QHttpNetworkReply::parseHeader(const QByteArray &header) +void QHttpNetworkReply::parseHeader(QByteArrayView header) { Q_D(QHttpNetworkReply); d->parseHeader(header); @@ -352,8 +318,7 @@ QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl) { QString scheme = newUrl.scheme(); - if (scheme == QLatin1String("preconnect-http") - || scheme == QLatin1String("preconnect-https")) + if (scheme == "preconnect-http"_L1 || scheme == "preconnect-https"_L1) // make sure we do not close the socket after preconnecting connectionCloseEnabled = false; } @@ -403,7 +368,7 @@ void QHttpNetworkReplyPrivate::removeAutoDecompressHeader() { // The header "Content-Encoding = gzip" is retained. // Content-Length is removed since the actual one sent by the server is for compressed data - QByteArray name("content-length"); + constexpr auto name = QByteArrayView("content-length"); QByteArray contentLength = parser.firstHeaderField(name); bool parseOk = false; qint64 value = contentLength.toLongLong(&parseOk); @@ -413,23 +378,7 @@ void QHttpNetworkReplyPrivate::removeAutoDecompressHeader() } } -bool QHttpNetworkReplyPrivate::findChallenge(bool forProxy, QByteArray &challenge) const -{ - challenge.clear(); - // find out the type of authentication protocol requested. - QByteArray header = forProxy ? "proxy-authenticate" : "www-authenticate"; - // pick the best protocol (has to match parsing in QAuthenticatorPrivate) - QList<QByteArray> challenges = headerFieldValues(header); - for (int i = 0; i<challenges.size(); i++) { - QByteArray line = challenges.at(i); - // todo use qstrincmp - if (!line.toLower().startsWith("negotiate")) - challenge = line; - } - return !challenge.isEmpty(); -} - -qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) +qint64 QHttpNetworkReplyPrivate::readStatus(QIODevice *socket) { if (fragment.isEmpty()) { // reserve bytes for the status line. This is better than always append() which reallocs the byte array @@ -455,7 +404,7 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) if (c == '\n') { // remove the CR at the end if (fragment.endsWith('\r')) { - fragment.truncate(fragment.length()-1); + fragment.truncate(fragment.size()-1); } bool ok = parseStatus(fragment); state = ReadingHeaderState; @@ -469,7 +418,7 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) } // is this a valid reply? - if (fragment.length() == 5 && !fragment.startsWith("HTTP/")) { + if (fragment.size() == 5 && !fragment.startsWith("HTTP/")) { fragment.clear(); return -1; } @@ -478,12 +427,12 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) return bytes; } -bool QHttpNetworkReplyPrivate::parseStatus(const QByteArray &status) +bool QHttpNetworkReplyPrivate::parseStatus(QByteArrayView status) { return parser.parseStatus(status); } -qint64 QHttpNetworkReplyPrivate::readHeader(QAbstractSocket *socket) +qint64 QHttpNetworkReplyPrivate::readHeader(QIODevice *socket) { if (fragment.isEmpty()) { // according to http://dev.opera.com/articles/view/mama-http-headers/ the average size of the header @@ -517,8 +466,8 @@ qint64 QHttpNetworkReplyPrivate::readHeader(QAbstractSocket *socket) allHeaders = true; // there is another case: We have no headers. Then the fragment equals just the line ending - if ((fragment.length() == 2 && fragment.endsWith("\r\n")) - || (fragment.length() == 1 && fragment.endsWith("\n"))) + if ((fragment.size() == 2 && fragment.endsWith("\r\n")) + || (fragment.size() == 1 && fragment.endsWith("\n"))) allHeaders = true; } } @@ -545,7 +494,7 @@ qint64 QHttpNetworkReplyPrivate::readHeader(QAbstractSocket *socket) return bytes; } -void QHttpNetworkReplyPrivate::parseHeader(const QByteArray &header) +void QHttpNetworkReplyPrivate::parseHeader(QByteArrayView header) { parser.parseHeaders(header); } @@ -567,7 +516,7 @@ bool QHttpNetworkReplyPrivate::isConnectionCloseEnabled() // note this function can only be used for non-chunked, non-compressed with // known content length -qint64 QHttpNetworkReplyPrivate::readBodyVeryFast(QAbstractSocket *socket, char *b) +qint64 QHttpNetworkReplyPrivate::readBodyVeryFast(QIODevice *socket, char *b) { // This first read is to flush the buffer inside the socket qint64 haveRead = 0; @@ -586,7 +535,7 @@ qint64 QHttpNetworkReplyPrivate::readBodyVeryFast(QAbstractSocket *socket, char // note this function can only be used for non-chunked, non-compressed with // known content length -qint64 QHttpNetworkReplyPrivate::readBodyFast(QAbstractSocket *socket, QByteDataBuffer *rb) +qint64 QHttpNetworkReplyPrivate::readBodyFast(QIODevice *socket, QByteDataBuffer *rb) { qint64 toBeRead = qMin(socket->bytesAvailable(), bodyLength - contentRead); @@ -616,7 +565,7 @@ qint64 QHttpNetworkReplyPrivate::readBodyFast(QAbstractSocket *socket, QByteData } -qint64 QHttpNetworkReplyPrivate::readBody(QAbstractSocket *socket, QByteDataBuffer *out) +qint64 QHttpNetworkReplyPrivate::readBody(QIODevice *socket, QByteDataBuffer *out) { qint64 bytes = 0; @@ -636,7 +585,7 @@ qint64 QHttpNetworkReplyPrivate::readBody(QAbstractSocket *socket, QByteDataBuff return bytes; } -qint64 QHttpNetworkReplyPrivate::readReplyBodyRaw(QAbstractSocket *socket, QByteDataBuffer *out, qint64 size) +qint64 QHttpNetworkReplyPrivate::readReplyBodyRaw(QIODevice *socket, QByteDataBuffer *out, qint64 size) { // FIXME get rid of this function and just use readBodyFast and give it socket->bytesAvailable() qint64 bytes = 0; @@ -669,7 +618,7 @@ qint64 QHttpNetworkReplyPrivate::readReplyBodyRaw(QAbstractSocket *socket, QByte } -qint64 QHttpNetworkReplyPrivate::readReplyBodyChunked(QAbstractSocket *socket, QByteDataBuffer *out) +qint64 QHttpNetworkReplyPrivate::readReplyBodyChunked(QIODevice *socket, QByteDataBuffer *out) { qint64 bytes = 0; while (socket->bytesAvailable()) { @@ -731,7 +680,7 @@ qint64 QHttpNetworkReplyPrivate::readReplyBodyChunked(QAbstractSocket *socket, Q return bytes; } -qint64 QHttpNetworkReplyPrivate::getChunkSize(QAbstractSocket *socket, qint64 *chunkSize) +qint64 QHttpNetworkReplyPrivate::getChunkSize(QIODevice *socket, qint64 *chunkSize) { qint64 bytes = 0; char crlf[2]; @@ -752,8 +701,8 @@ qint64 QHttpNetworkReplyPrivate::getChunkSize(QAbstractSocket *socket, qint64 *c bytes += socket->read(crlf, 1); // read the \n bool ok = false; // ignore the chunk-extension - fragment = fragment.mid(0, fragment.indexOf(';')).trimmed(); - *chunkSize = fragment.toLong(&ok, 16); + const auto fragmentView = QByteArrayView(fragment).mid(0, fragment.indexOf(';')).trimmed(); + *chunkSize = fragmentView.toLong(&ok, 16); fragment.clear(); break; // size done } else { @@ -855,3 +804,5 @@ void QHttpNetworkReply::ignoreSslErrors(const QList<QSslError> &errors) QT_END_NAMESPACE + +#include "moc_qhttpnetworkreply_p.cpp" |