[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kio/kio
From: Dawit Alemayehu <adawit () kde ! org>
Date: 2010-12-21 7:27:18
Message-ID: 20101221072718.27C45AC8AA () svn ! kde ! org
[Download RAW message or body]
SVN commit 1208315 by adawit:
- Don't rely on the "responsecode" meta-data to set the HTTP status and reason
phrase informations. Instead obtain that information from the returned HTTP
header directly.
- Flatened all the nested if statements in readHttpResponseHeaders as much as
possible.
- Emit the metaDataChanged signal upon reading the HTTP header information.
- Ensure the error state is set to NoError on creation of AccessMangerReply.
Note that all of these changes are preparation for addressing a long standing
KIO-QNAM integration bug ; the inability to put ioslaves on hold so that they
can be handed from one app/component to another.
M +29 -31 accessmanagerreply_p.cpp
--- trunk/KDE/kdelibs/kio/kio/accessmanagerreply_p.cpp #1208314:1208315
@@ -49,6 +49,7 @@
setOpenMode(QIODevice::ReadOnly);
setUrl(request.url());
setOperation(op);
+ setError(NoError, QString());
if (!request.sslConfiguration().isNull())
setSslConfiguration(request.sslConfiguration());
@@ -73,9 +74,8 @@
void AccessManagerReply::abort()
{
- if (m_kioJob) {
+ if (m_kioJob)
m_kioJob->kill();
- }
m_data.clear();
m_metaDataRead = false;
@@ -98,7 +98,6 @@
return length;
}
-
void AccessManagerReply::setStatus(const QString& message, \
QNetworkReply::NetworkError code) {
setError(code, message);
@@ -106,38 +105,42 @@
void AccessManagerReply::readHttpResponseHeaders(KIO::Job *job)
{
- if (!m_metaDataRead) {
- // Set the HTTP status code...
- const QString responseCode = job->queryMetaData(QL1S("responsecode"));
- if (!responseCode.isEmpty())
- setAttribute(QNetworkRequest::HttpStatusCodeAttribute, \
responseCode.toInt()); + if (m_metaDataRead)
+ return;
+ const KIO::MetaData& metaData = job->metaData();
+ if (metaData.isEmpty())
+ return;
+
// Set the encryption attribute and values...
QSslConfiguration sslConfig;
- const bool isEncrypted = \
KIO::Integration::sslConfigFromMetaData(job->metaData(), sslConfig); + const bool \
isEncrypted = KIO::Integration::sslConfigFromMetaData(metaData, \
sslConfig);
setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, isEncrypted);
if (isEncrypted)
setSslConfiguration(sslConfig);
+ // Set the returned meta data as attribute...
+ setAttribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData),
+ metaData.toVariant());
+
// Set the raw header information...
- const QStringList httpHeaders \
(job->queryMetaData(QL1S("HTTP-Headers")).split(QL1C('\n'))); + const QStringList \
httpHeaders (metaData.value(QL1S("HTTP-Headers")).split(QL1C('\n'), \
QString::SkipEmptyParts)); Q_FOREACH(const QString& httpHeader, httpHeaders) {
int index = httpHeader.indexOf(QL1C(':'));
- // Ignore the HTTP status line...
+ // Handle HTTP status line...
if (index == -1) {
- // Except for the status line, all HTTP headers must be a name/value \
pair,i.e "<name>:<value>" + // Except for the status line, all HTTP header \
must be an nvpair of + // type "<name>:<value>"
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)
- continue;
+ QStringList statusLineAttrs (httpHeader.split(QL1C(' '), \
QString::SkipEmptyParts)); + if (statusLineAttrs.count() > 1)
+ setAttribute(QNetworkRequest::HttpStatusCodeAttribute, \
statusLineAttrs.at(1));
- // Assign the status/reason pharse...
- index += responseCode.length();
- if (index < httpHeader.length())
- setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, \
httpHeader.mid(index).trimmed()); + if (statusLineAttrs.count() > 2)
+ setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, \
statusLineAttrs.at(2)); +
continue;
}
@@ -162,20 +165,16 @@
}
}
- // kDebug(7044) << "Adding header:" << headerName << ":" << headerValue;
setRawHeader(headerName.trimmed().toUtf8(), \
headerValue.trimmed().toUtf8()); }
- // Set the returned meta data as attribute...
- setAttribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData),
- job->metaData().toVariant());
m_metaDataRead = true;
+ emit metaDataChanged();
}
-}
void AccessManagerReply::slotData(KIO::Job *kioJob, const QByteArray &data)
{
- readHttpResponseHeaders(kioJob);
+ Q_UNUSED(kioJob);
m_data += data;
emit readyRead();
}
@@ -184,11 +183,12 @@
{
Q_UNUSED(kioJob);
setHeader(QNetworkRequest::ContentTypeHeader, mimeType.toUtf8());
+ readHttpResponseHeaders(kioJob);
}
void AccessManagerReply::slotResult(KJob *kJob)
{
- int errcode = kJob->error();
+ const int errcode = kJob->error();
switch (errcode)
{
case 0:
@@ -248,15 +248,13 @@
}
const QUrl redirectUrl = \
attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
- if (redirectUrl.isValid()) {
+ if (redirectUrl.isValid())
readHttpResponseHeaders(m_kioJob);
- //kDebug(7044) << "HTTP Status code:" << \
attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- //kDebug(7044) << "Redirecting to" << redirectUrl;
- }
setAttribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::KioError), \
errcode); if (errcode)
emit error(error());
+
emit finished();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic