~ubuntu-branches/ubuntu/natty/kde4libs/natty-proposed

« back to all changes in this revision

Viewing changes to kio/kio/accessmanagerreply_p.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell, Jonathan Riddell, Scott Kitterman
  • Date: 2011-01-21 11:32:24 UTC
  • mfrom: (1.14.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110121113224-c9tebdkklj5u3awu
Tags: 4:4.6.0-0ubuntu1~ppa1
[ Jonathan Riddell ]
* New upstream release
* Reluctantly add kcm_ssl to kdelibs5-plugins, this should be in kdebase

[ Scott Kitterman ]
* Update libkatepartinterfaces4.symbols and libkdecore5.symbols for 4.5.95
  and confirm symbols on all architectures with pkgkde-symbolshelper
  - Thanks to Jonathan Thomas for verifying the missing symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "job.h"
28
28
 
29
29
#include <kdebug.h>
 
30
#include <kprotocolinfo.h>
30
31
 
31
32
#include <QtNetwork/QSslConfiguration>
32
33
 
34
35
#define QL1C(x)  QLatin1Char(x)
35
36
 
36
37
 
 
38
static bool accessManager_isLocalRequest(const KUrl& url)
 
39
{
 
40
    const QString scheme (url.protocol());
 
41
    return (KProtocolInfo::isKnownProtocol(scheme) &&
 
42
            KProtocolInfo::protocolClass(scheme).compare(QL1S(":local"), Qt::CaseInsensitive) == 0);
 
43
}
 
44
 
37
45
namespace KDEPrivate {
38
46
 
39
47
AccessManagerReply::AccessManagerReply(const QNetworkAccessManager::Operation &op,
41
49
                                       KIO::SimpleJob *kioJob,
42
50
                                       QObject *parent)
43
51
                   :QNetworkReply(parent),
44
 
                    m_metaDataRead(false)
 
52
                    m_metaDataRead(false),
 
53
                    m_ignoreContentDisposition(false)
45
54
 
46
55
{
47
56
    m_kioJob = kioJob;
98
107
    return length;
99
108
}
100
109
 
 
110
void AccessManagerReply::setIgnoreContentDisposition(bool on)
 
111
{
 
112
    kDebug(7044) << on;
 
113
    m_ignoreContentDisposition = on;
 
114
}
 
115
 
101
116
void AccessManagerReply::setStatus(const QString& message, QNetworkReply::NetworkError code)
102
117
{
103
118
    setError(code, message);
104
119
}
105
120
 
 
121
void AccessManagerReply::putOnHold()
 
122
{
 
123
    if (!m_kioJob)
 
124
        return;
 
125
 
 
126
    m_kioJob->putOnHold();
 
127
}
 
128
 
 
129
static bool isStatusCodeSuccess(const QNetworkReply* reply)
 
130
{
 
131
    bool ok = false;
 
132
    const int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(&ok);
 
133
    if (!ok || statusCode < 200 || statusCode > 299)
 
134
        return false;
 
135
    return true;
 
136
}
 
137
 
106
138
void AccessManagerReply::readHttpResponseHeaders(KIO::Job *job)
107
139
{
108
 
    if (m_metaDataRead)
 
140
    if (!job || m_metaDataRead)
109
141
        return;
110
142
 
111
143
    const KIO::MetaData& metaData = job->metaData();
112
 
    if (metaData.isEmpty())
 
144
    if (metaData.isEmpty()) {
 
145
        // Allow handling of local resources such as man pages and file url...
 
146
        if (accessManager_isLocalRequest(url())) {
 
147
            setHeader(QNetworkRequest::ContentLengthHeader, job->totalAmount(KJob::Bytes));
 
148
            setAttribute(QNetworkRequest::HttpStatusCodeAttribute, "200");
 
149
            emit metaDataChanged();
 
150
        }        
113
151
        return;
 
152
    }
114
153
 
115
154
    // Set the encryption attribute and values...
116
155
    QSslConfiguration sslConfig;
151
190
        if (headerName.startsWith(QL1S("set-cookie"), Qt::CaseInsensitive))
152
191
            continue;
153
192
 
 
193
        if (headerName.startsWith(QL1S("content-disposition"), Qt::CaseInsensitive) &&
 
194
            (m_ignoreContentDisposition || !isStatusCodeSuccess(this)))
 
195
            continue;
 
196
 
154
197
        // Without overridding the corrected mime-type sent by kio_http, add
155
198
        // back the "charset=" portion of the content-type header if present.
156
199
        if (headerName.startsWith(QL1S("content-type"), Qt::CaseInsensitive)) {
174
217
 
175
218
void AccessManagerReply::slotData(KIO::Job *kioJob, const QByteArray &data)
176
219
{
177
 
    // FIXME: Remove the line below when kio_http is fixed to do the correct thing!
178
 
    readHttpResponseHeaders(kioJob);
 
220
    Q_UNUSED (kioJob);
179
221
    m_data += data;
180
222
    emit readyRead();
181
223
}
182
224
 
183
225
void AccessManagerReply::slotMimeType(KIO::Job *kioJob, const QString &mimeType)
184
226
{
185
 
    Q_UNUSED(kioJob);
 
227
    kDebug(7044) << kioJob << mimeType;
186
228
    setHeader(QNetworkRequest::ContentTypeHeader, mimeType.toUtf8());
187
229
    readHttpResponseHeaders(kioJob);
188
230
}