From kde-commits Wed Dec 01 00:10:35 2010 From: Dawit Alemayehu Date: Wed, 01 Dec 2010 00:10:35 +0000 To: kde-commits Subject: KDE/kdelibs/kio/kio Message-Id: <20101201001035.1A986AC8A3 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=129116228408602 SVN commit 1202463 by adawit: Reduced if statement nesting where possible M +17 -12 accessmanagerreply_p.cpp --- trunk/KDE/kdelibs/kio/kio/accessmanagerreply_p.cpp #1202462:1202463 @@ -120,29 +120,34 @@ setSslConfiguration(sslConfig); // Set the raw header information... - const QString headers = job->queryMetaData(QL1S("HTTP-Headers")); - if (!headers.isEmpty()) { - const QStringList httpHeaders (headers.split(QL1C('\n'))); + const QStringList httpHeaders (job->queryMetaData(QL1S("HTTP-Headers")).split(QL1C('\n'))); Q_FOREACH(const QString& httpHeader, httpHeaders) { int index = httpHeader.indexOf(QL1C(':')); // Ignore the HTTP status line... - if (index == -1 && httpHeader.startsWith(QL1S("HTTP/"), Qt::CaseInsensitive)) { + if (index == -1) { + // Except for the status line, all HTTP headers must be a name/value pair,i.e ":" + if (!httpHeader.startsWith(QL1S("HTTP/"), Qt::CaseInsensitive)) + continue; + + // Further validate the status line to make sure it contains the response code... index = httpHeader.indexOf(responseCode); - if (index > -1) { + if (index == -1) + continue; + + // Assign the status/reason pharse... index += responseCode.length(); - if (index < httpHeader.length()) { - const QString& reasonPhrase = httpHeader.mid(index).trimmed(); - setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, reasonPhrase); - //kDebug(7044) << "Set reason phrase to" << reasonPhrase; - } - } + if (index < httpHeader.length()) + setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, httpHeader.mid(index).trimmed()); continue; } + const QString headerName = httpHeader.left(index); QString headerValue = httpHeader.mid(index+1); + // Skip setting cookies since they are automatically handled by kio_http... if (headerName.startsWith(QL1S("set-cookie"), Qt::CaseInsensitive)) continue; + // Without overridding the corrected mime-type sent by kio_http, add // back the "charset=" portion of the content-type header if present. if (headerName.startsWith(QL1S("content-type"), Qt::CaseInsensitive)) { @@ -156,10 +161,10 @@ //kDebug(7044) << "Changed mime-type from" << mimeType << "to" << headerValue; } } + // kDebug(7044) << "Adding header:" << headerName << ":" << headerValue; setRawHeader(headerName.trimmed().toUtf8(), headerValue.trimmed().toUtf8()); } - } // Set the returned meta data as attribute... setAttribute(static_cast(KIO::AccessManager::MetaData),