Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/http/http.cpp
Show All 29 Lines | |||||
30 | 30 | | |||
31 | #include <config-kioslave-http.h> | 31 | #include <config-kioslave-http.h> | ||
32 | 32 | | |||
33 | #include <qplatformdefs.h> // must be explicitly included for MacOSX | 33 | #include <qplatformdefs.h> // must be explicitly included for MacOSX | ||
34 | 34 | | |||
35 | #include <qdom.h> | 35 | #include <qdom.h> | ||
36 | #include <QFile> | 36 | #include <QFile> | ||
37 | #include <QLibraryInfo> | 37 | #include <QLibraryInfo> | ||
38 | #include <QRegExp> | 38 | #include <QRegularExpression> | ||
39 | #include <QDateTime> | 39 | #include <QDateTime> | ||
40 | #include <QBuffer> | 40 | #include <QBuffer> | ||
41 | #include <QIODevice> | 41 | #include <QIODevice> | ||
42 | #include <QTemporaryFile> | 42 | #include <QTemporaryFile> | ||
43 | #include <QStandardPaths> | 43 | #include <QStandardPaths> | ||
44 | #include <QMimeDatabase> | 44 | #include <QMimeDatabase> | ||
45 | #include <QAuthenticator> | 45 | #include <QAuthenticator> | ||
46 | #include <QNetworkProxy> | 46 | #include <QNetworkProxy> | ||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | |||||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | /* | 161 | /* | ||
162 | Eliminates any custom header that could potentially alter the request | 162 | Eliminates any custom header that could potentially alter the request | ||
163 | */ | 163 | */ | ||
164 | static QString sanitizeCustomHTTPHeader(const QString &_header) | 164 | static QString sanitizeCustomHTTPHeader(const QString &_header) | ||
165 | { | 165 | { | ||
166 | QString sanitizedHeaders; | 166 | QString sanitizedHeaders; | ||
167 | const QStringList headers = _header.split(QRegExp(QStringLiteral("[\r\n]"))); | 167 | const QVector<QStringRef> headers = _header.splitRef(QRegularExpression(QStringLiteral("[\r\n]"))); | ||
168 | 168 | | |||
169 | for (const QString &header : headers) { | 169 | for (const QStringRef &header : headers) { | ||
170 | // Do not allow Request line to be specified and ignore | 170 | // Do not allow Request line to be specified and ignore | ||
171 | // the other HTTP headers. | 171 | // the other HTTP headers. | ||
172 | if (!header.contains(QLatin1Char(':')) || | 172 | if (!header.contains(QLatin1Char(':')) || | ||
173 | header.startsWith(QLatin1String("host"), Qt::CaseInsensitive) || | 173 | header.startsWith(QLatin1String("host"), Qt::CaseInsensitive) || | ||
174 | header.startsWith(QLatin1String("proxy-authorization"), Qt::CaseInsensitive) || | 174 | header.startsWith(QLatin1String("proxy-authorization"), Qt::CaseInsensitive) || | ||
175 | header.startsWith(QLatin1String("via"), Qt::CaseInsensitive) || | 175 | header.startsWith(QLatin1String("via"), Qt::CaseInsensitive) || | ||
176 | header.startsWith(QLatin1String("depth"), Qt::CaseInsensitive)) { | 176 | header.startsWith(QLatin1String("depth"), Qt::CaseInsensitive)) { | ||
177 | continue; | 177 | continue; | ||
▲ Show 20 Lines • Show All 3097 Lines • ▼ Show 20 Line(s) | 3274 | if (tIt.hasNext()) { | |||
3275 | // We only support Link: <url>; rel="type" so far | 3275 | // We only support Link: <url>; rel="type" so far | ||
3276 | QStringList link = toQString(tIt.next()).split(QLatin1Char(';'), QString::SkipEmptyParts); | 3276 | QStringList link = toQString(tIt.next()).split(QLatin1Char(';'), QString::SkipEmptyParts); | ||
3277 | if (link.count() == 2) { | 3277 | if (link.count() == 2) { | ||
3278 | QString rel = link[1].trimmed(); | 3278 | QString rel = link[1].trimmed(); | ||
3279 | if (rel.startsWith(QLatin1String("rel=\""))) { | 3279 | if (rel.startsWith(QLatin1String("rel=\""))) { | ||
3280 | rel = rel.mid(5, rel.length() - 6); | 3280 | rel = rel.mid(5, rel.length() - 6); | ||
3281 | if (rel.toLower() == QLatin1String("pageservices")) { | 3281 | if (rel.toLower() == QLatin1String("pageservices")) { | ||
3282 | //### the remove() part looks fishy! | 3282 | //### the remove() part looks fishy! | ||
3283 | QString url = link[0].remove(QRegExp(QStringLiteral("[<>]"))).trimmed(); | 3283 | QString url = link[0].remove(QRegularExpression(QStringLiteral("[<>]"))).trimmed(); | ||
3284 | setMetaData(QStringLiteral("PageServices"), url); | 3284 | setMetaData(QStringLiteral("PageServices"), url); | ||
3285 | } | 3285 | } | ||
3286 | } | 3286 | } | ||
3287 | } | 3287 | } | ||
3288 | } | 3288 | } | ||
3289 | 3289 | | |||
3290 | tIt = tokenizer.iterator("p3p"); | 3290 | tIt = tokenizer.iterator("p3p"); | ||
3291 | if (tIt.hasNext()) { | 3291 | if (tIt.hasNext()) { | ||
3292 | // P3P privacy policy information | 3292 | // P3P privacy policy information | ||
3293 | QStringList policyrefs, compact; | 3293 | QStringList policyrefs, compact; | ||
3294 | while (tIt.hasNext()) { | 3294 | while (tIt.hasNext()) { | ||
3295 | QStringList policy = toQString(tIt.next().simplified()) | 3295 | QStringList policy = toQString(tIt.next().simplified()) | ||
3296 | .split(QLatin1Char('='), QString::SkipEmptyParts); | 3296 | .split(QLatin1Char('='), QString::SkipEmptyParts); | ||
3297 | if (policy.count() == 2) { | 3297 | if (policy.count() == 2) { | ||
3298 | if (policy[0].toLower() == QLatin1String("policyref")) { | 3298 | if (policy[0].toLower() == QLatin1String("policyref")) { | ||
3299 | policyrefs << policy[1].remove(QRegExp(QStringLiteral("[\")\']"))).trimmed(); | 3299 | policyrefs << policy[1].remove(QRegularExpression(QStringLiteral("[\")\']"))).trimmed(); | ||
3300 | } else if (policy[0].toLower() == QLatin1String("cp")) { | 3300 | } else if (policy[0].toLower() == QLatin1String("cp")) { | ||
3301 | // We convert to cp\ncp\ncp\n[...]\ncp to be consistent with | 3301 | // We convert to cp\ncp\ncp\n[...]\ncp to be consistent with | ||
3302 | // other metadata sent in strings. This could be a bit more | 3302 | // other metadata sent in strings. This could be a bit more | ||
3303 | // efficient but I'm going for correctness right now. | 3303 | // efficient but I'm going for correctness right now. | ||
3304 | const QString s = policy[1].remove(QRegExp(QStringLiteral("[\")\']"))); | 3304 | const QString s = policy[1].remove(QRegularExpression(QStringLiteral("[\")\']"))); | ||
3305 | const QStringList cps = s.split(QLatin1Char(' '), QString::SkipEmptyParts); | 3305 | const QStringList cps = s.split(QLatin1Char(' '), QString::SkipEmptyParts); | ||
3306 | compact << cps; | 3306 | compact << cps; | ||
3307 | } | 3307 | } | ||
3308 | } | 3308 | } | ||
3309 | } | 3309 | } | ||
3310 | if (!policyrefs.isEmpty()) { | 3310 | if (!policyrefs.isEmpty()) { | ||
3311 | setMetaData(QStringLiteral("PrivacyPolicy"), policyrefs.join(QLatin1Char('\n'))); | 3311 | setMetaData(QStringLiteral("PrivacyPolicy"), policyrefs.join(QLatin1Char('\n'))); | ||
3312 | } | 3312 | } | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
3362 | } | 3362 | } | ||
3363 | 3363 | | |||
3364 | // Now process the HTTP/1.1 upgrade | 3364 | // Now process the HTTP/1.1 upgrade | ||
3365 | QStringList upgradeOffers; | 3365 | QStringList upgradeOffers; | ||
3366 | tIt = tokenizer.iterator("upgrade"); | 3366 | tIt = tokenizer.iterator("upgrade"); | ||
3367 | if (tIt.hasNext()) { | 3367 | if (tIt.hasNext()) { | ||
3368 | // Now we have to check to see what is offered for the upgrade | 3368 | // Now we have to check to see what is offered for the upgrade | ||
3369 | QString offered = toQString(tIt.next()); | 3369 | QString offered = toQString(tIt.next()); | ||
3370 | upgradeOffers = offered.split(QRegExp(QStringLiteral("[ \n,\r\t]")), QString::SkipEmptyParts); | 3370 | upgradeOffers = offered.split(QRegularExpression(QStringLiteral("[ \n,\r\t]")), QString::SkipEmptyParts); | ||
3371 | } | 3371 | } | ||
3372 | for (const QString &opt : qAsConst(upgradeOffers)) { | 3372 | for (const QString &opt : qAsConst(upgradeOffers)) { | ||
3373 | if (opt == QLatin1String("TLS/1.0")) { | 3373 | if (opt == QLatin1String("TLS/1.0")) { | ||
3374 | if (!startSsl() && upgradeRequired) { | 3374 | if (!startSsl() && upgradeRequired) { | ||
3375 | error(ERR_UPGRADE_REQUIRED, opt); | 3375 | error(ERR_UPGRADE_REQUIRED, opt); | ||
3376 | return false; | 3376 | return false; | ||
3377 | } | 3377 | } | ||
3378 | } else if (opt == QLatin1String("HTTP/1.1")) { | 3378 | } else if (opt == QLatin1String("HTTP/1.1")) { | ||
▲ Show 20 Lines • Show All 2250 Lines • Show Last 20 Lines |