mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kio: remove redundant KIO::SlaveBase methods
assume there is no metadata if empty, otherwise it is 2x the trip - one time to check and one time to get the metadata Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
0adda2b5e2
commit
1a5f247e86
3 changed files with 21 additions and 52 deletions
|
@ -350,22 +350,6 @@ QString SlaveBase::metaData(const QString &key) const
|
|||
return QString();
|
||||
}
|
||||
|
||||
MetaData SlaveBase::allMetaData() const
|
||||
{
|
||||
return d->m_incomingMetaData;
|
||||
}
|
||||
|
||||
bool SlaveBase::hasMetaData(const QString &key) const
|
||||
{
|
||||
if (d->m_incomingMetaData.contains(key)) {
|
||||
return true;
|
||||
}
|
||||
if (d->configData.contains(key)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
KConfigGroup *SlaveBase::config()
|
||||
{
|
||||
return d->configGroup;
|
||||
|
|
|
@ -237,24 +237,12 @@ public:
|
|||
* data() or finished() signal.
|
||||
*/
|
||||
void setMetaData(const QString &key, const QString &value);
|
||||
|
||||
/**
|
||||
* Queries for the existence of a certain config/meta-data entry
|
||||
* send by the application to the slave.
|
||||
*/
|
||||
bool hasMetaData(const QString &key) const;
|
||||
|
||||
/**
|
||||
* Queries for config/meta-data send by the application to the slave.
|
||||
*/
|
||||
QString metaData(const QString &key) const;
|
||||
|
||||
|
||||
/**
|
||||
* Contains all metadata (but no config) sent by the application to the slave.
|
||||
*/
|
||||
MetaData allMetaData() const;
|
||||
|
||||
/**
|
||||
* Returns a configuration object to query config/meta-data information
|
||||
* from.
|
||||
|
|
|
@ -537,9 +537,9 @@ void CurlProtocol::get(const KUrl &url)
|
|||
}
|
||||
|
||||
CURLcode curlresult = CURLE_OK;
|
||||
if (hasMetaData(QLatin1String("resume"))) {
|
||||
Q_ASSERT(sizeof(qlonglong) == sizeof(curl_off_t));
|
||||
const qlonglong resumeoffset = metaData(QLatin1String("resume")).toLongLong();
|
||||
const qlonglong resumeoffset = metaData(QLatin1String("resume")).toLongLong();
|
||||
if (resumeoffset > 0) {
|
||||
Q_ASSERT(sizeof(qlonglong) == sizeof(curl_off_t));;
|
||||
kDebug(7103) << "Resume offset" << resumeoffset;
|
||||
curlresult = curl_easy_setopt(m_curl, CURLOPT_RESUME_FROM_LARGE, curl_off_t(resumeoffset));
|
||||
if (curlresult != CURLE_OK) {
|
||||
|
@ -966,15 +966,12 @@ bool CurlProtocol::setupCurl(const KUrl &url, const bool ftp)
|
|||
}
|
||||
#endif
|
||||
|
||||
kDebug(7103) << "Metadata" << allMetaData();
|
||||
|
||||
if (hasMetaData(QLatin1String("UserAgent"))) {
|
||||
const QByteArray useragentbytes = metaData("UserAgent").toAscii();
|
||||
curlresult = curl_easy_setopt(m_curl, CURLOPT_USERAGENT, useragentbytes.constData());
|
||||
if (curlresult != CURLE_OK) {
|
||||
KIO_CURL_ERROR(curlresult);
|
||||
return false;
|
||||
}
|
||||
// should not be empty, see KIO::Scheduler
|
||||
const QByteArray useragentbytes = metaData("UserAgent").toAscii();
|
||||
curlresult = curl_easy_setopt(m_curl, CURLOPT_USERAGENT, useragentbytes.constData());
|
||||
if (curlresult != CURLE_OK) {
|
||||
KIO_CURL_ERROR(curlresult);
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool noauth = (metaData("no-auth") == QLatin1String("yes"));
|
||||
|
@ -1007,20 +1004,20 @@ bool CurlProtocol::setupCurl(const KUrl &url, const bool ftp)
|
|||
m_curlheaders = nullptr;
|
||||
}
|
||||
if (m_ishttp) {
|
||||
if (hasMetaData(QLatin1String("Languages"))) {
|
||||
m_curlheaders = curl_slist_append(m_curlheaders, QByteArray("Accept-Language: ") + metaData("Languages").toAscii());
|
||||
// also should not be empty, see KIO::Scheduler
|
||||
const QByteArray languagesbytes = metaData("Languages").toAscii();
|
||||
m_curlheaders = curl_slist_append(m_curlheaders, QByteArray("Accept-Language: ") + languagesbytes);
|
||||
const QByteArray charsetsbytes = metaData("Charsets").toAscii();
|
||||
m_curlheaders = curl_slist_append(m_curlheaders, QByteArray("Accept-Charset: ") + charsetsbytes);
|
||||
|
||||
const QByteArray acceptbytes = metaData("accept").toAscii();
|
||||
if (!acceptbytes.isEmpty()) {
|
||||
m_curlheaders = curl_slist_append(m_curlheaders, QByteArray("Accept: ") + acceptbytes);
|
||||
}
|
||||
|
||||
if (hasMetaData(QLatin1String("Charsets"))) {
|
||||
m_curlheaders = curl_slist_append(m_curlheaders, QByteArray("Accept-Charset: ") + metaData("Charsets").toAscii());
|
||||
}
|
||||
|
||||
if (hasMetaData(QLatin1String("accept"))) {
|
||||
m_curlheaders = curl_slist_append(m_curlheaders, QByteArray("Accept: ") + metaData("accept").toAscii());
|
||||
}
|
||||
|
||||
if (hasMetaData(QLatin1String("Authorization"))) {
|
||||
m_curlheaders = curl_slist_append(m_curlheaders, QByteArray("Authorization: ") + metaData("Authorization").toAscii());
|
||||
const QByteArray authorizationbytes = metaData("Authorization").toAscii();
|
||||
if (!authorizationbytes.isEmpty()) {
|
||||
m_curlheaders = curl_slist_append(m_curlheaders, QByteArray("Authorization: ") + authorizationbytes);
|
||||
}
|
||||
|
||||
curlresult = curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, m_curlheaders);
|
||||
|
|
Loading…
Add table
Reference in a new issue