qnetworkrequest: extract method
for If-Match and If-None-Match parsing Change-Id: I523f5c639a01bafe6f25f13c0d25b3c62fa75282 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
881260f9e4
commit
e3bb75340e
@ -1219,7 +1219,8 @@ static QVariant parseETag(QByteArrayView raw)
|
|||||||
return QString::fromLatin1(trimmed);
|
return QString::fromLatin1(trimmed);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVariant parseIfMatch(const QByteArray &raw)
|
template<typename T>
|
||||||
|
static QVariant parseMatchImpl(const QByteArray &raw, T op)
|
||||||
{
|
{
|
||||||
const QByteArray trimmedRaw = raw.trimmed();
|
const QByteArray trimmedRaw = raw.trimmed();
|
||||||
if (trimmedRaw == "*")
|
if (trimmedRaw == "*")
|
||||||
@ -1229,36 +1230,25 @@ static QVariant parseIfMatch(const QByteArray &raw)
|
|||||||
const QList<QByteArray> split = trimmedRaw.split(',');
|
const QList<QByteArray> split = trimmedRaw.split(',');
|
||||||
for (const QByteArray &element : split) {
|
for (const QByteArray &element : split) {
|
||||||
const QByteArray trimmed = element.trimmed();
|
const QByteArray trimmed = element.trimmed();
|
||||||
if (!trimmed.startsWith('"'))
|
if (!op(trimmed))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!trimmed.endsWith('"'))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
tags += QString::fromLatin1(trimmed);
|
tags += QString::fromLatin1(trimmed);
|
||||||
}
|
}
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QVariant parseIfMatch(const QByteArray &raw)
|
||||||
|
{
|
||||||
|
return parseMatchImpl(raw, [](QByteArrayView element) {
|
||||||
|
return element.startsWith('"') && element.endsWith('"');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static QVariant parseIfNoneMatch(const QByteArray &raw)
|
static QVariant parseIfNoneMatch(const QByteArray &raw)
|
||||||
{
|
{
|
||||||
const QByteArray trimmedRaw = raw.trimmed();
|
return parseMatchImpl(raw, [](QByteArrayView element) {
|
||||||
if (trimmedRaw == "*")
|
return (element.startsWith('"') || element.startsWith(R"(W/")")) && element.endsWith('"');
|
||||||
return QStringList(QStringLiteral("*"));
|
});
|
||||||
|
|
||||||
QStringList tags;
|
|
||||||
const QList<QByteArray> split = trimmedRaw.split(',');
|
|
||||||
for (const QByteArray &element : split) {
|
|
||||||
const QByteArray trimmed = element.trimmed();
|
|
||||||
if (!trimmed.startsWith('"') && !trimmed.startsWith(R"(W/")"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!trimmed.endsWith('"'))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
tags += QString::fromLatin1(trimmed);
|
|
||||||
}
|
|
||||||
return tags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user