qnetworkreplyhttpimpl: use range based for more

to improve readability. While touching code, remove needless copy of container

Change-Id: I04e44819621b5ea9a71f89352e8dd25d4c41de3d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Anton Kudryavtsev 2023-08-31 11:54:13 +03:00
parent 50f24f7152
commit 51acd52cf7

View File

@ -1343,25 +1343,22 @@ void QNetworkReplyHttpImplPrivate::replyDownloadMetaData(const QList<QPair<QByte
const bool autoDecompress = request.rawHeader("accept-encoding").isEmpty(); const bool autoDecompress = request.rawHeader("accept-encoding").isEmpty();
const bool shouldDecompress = isCompressed && autoDecompress; const bool shouldDecompress = isCompressed && autoDecompress;
// reconstruct the HTTP header // reconstruct the HTTP header
QList<QPair<QByteArray, QByteArray> > headerMap = hm; for (const auto &[key, originValue] : hm) {
QList<QPair<QByteArray, QByteArray> >::ConstIterator it = headerMap.constBegin(), QByteArray value = q->rawHeader(key);
end = headerMap.constEnd();
for (; it != end; ++it) {
QByteArray value = q->rawHeader(it->first);
// Reset any previous "location" header set in the reply. In case of // Reset any previous "location" header set in the reply. In case of
// redirects, we don't want to 'append' multiple location header values, // redirects, we don't want to 'append' multiple location header values,
// rather we keep only the latest one // rather we keep only the latest one
if (it->first.toLower() == "location") if (key.toLower() == "location")
value.clear(); value.clear();
if (shouldDecompress && !decompressHelper.isValid() if (shouldDecompress && !decompressHelper.isValid()
&& it->first.compare("content-encoding", Qt::CaseInsensitive) == 0) { && key.compare("content-encoding", Qt::CaseInsensitive) == 0) {
if (!synchronous) // with synchronous all the data is expected to be handled at once if (!synchronous) // with synchronous all the data is expected to be handled at once
decompressHelper.setCountingBytesEnabled(true); decompressHelper.setCountingBytesEnabled(true);
if (!decompressHelper.setEncoding(it->second)) { if (!decompressHelper.setEncoding(originValue)) {
error(QNetworkReplyImpl::NetworkError::UnknownContentError, error(QNetworkReplyImpl::NetworkError::UnknownContentError,
QCoreApplication::translate("QHttp", "Failed to initialize decompression: %1") QCoreApplication::translate("QHttp", "Failed to initialize decompression: %1")
.arg(decompressHelper.errorString())); .arg(decompressHelper.errorString()));
@ -1374,13 +1371,13 @@ void QNetworkReplyHttpImplPrivate::replyDownloadMetaData(const QList<QPair<QByte
if (!value.isEmpty()) { if (!value.isEmpty()) {
// Why are we appending values for headers which are already // Why are we appending values for headers which are already
// present? // present?
if (it->first.compare("set-cookie", Qt::CaseInsensitive) == 0) if (key.compare("set-cookie", Qt::CaseInsensitive) == 0)
value += '\n'; value += '\n';
else else
value += ", "; value += ", ";
} }
value += it->second; value += originValue;
q->setRawHeader(it->first, value); q->setRawHeader(key, value);
} }
q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, statusCode); q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, statusCode);