25 return std::find_if(headers.cbegin(), headers.cend(), matchKey);
30 : m_data(other.m_data)
36 return header(
"Content-Disposition");
60 return header(
"Content-Encoding");
65 setHeader(
"Content-Encoding"_ba, encoding);
90 ret =
contentType.mid(pos + 8, endPos).trimmed().toUpper();
99 auto result = findHeaderConst(m_data,
"Content-Type");
100 if (result == m_data.end() || (result->value.isEmpty() && !charset.
isEmpty())) {
124 }
else if (!charset.
isEmpty()) {
138 return ct.
compare(
"text/html") == 0 || ct.
compare(
"application/xhtml+xml") == 0 ||
139 ct.
compare(
"application/vnd.wap.xhtml+xml") == 0;
145 return ct.
compare(
"application/xhtml+xml") == 0 ||
146 ct.
compare(
"application/vnd.wap.xhtml+xml") == 0;
157 auto value =
header(
"Content-Type");
158 if (!value.isEmpty()) {
159 return value.compare(
"application/json") == 0;
166 auto value =
header(
"Content-Length");
167 if (!value.isEmpty()) {
168 return value.toLongLong();
191 auto value =
header(
"Date");
192 if (!value.isEmpty()) {
193 if (value.endsWith(
" GMT")) {
195 QStringLiteral(
"ddd, dd MMM yyyy hh:mm:ss"));
198 QStringLiteral(
"ddd, dd MMM yyyy hh:mm:ss"));
208 return header(
"If-Modified-Since");
214 auto value =
header(
"If-Modified-Since");
215 if (!value.isEmpty()) {
216 if (value.endsWith(
" GMT")) {
218 QStringLiteral(
"ddd, dd MMM yyyy hh:mm:ss"));
221 QStringLiteral(
"ddd, dd MMM yyyy hh:mm:ss"));
231 auto value =
header(
"If-Modified-Since");
232 if (!value.isEmpty()) {
242 auto value =
header(
"If-Match");
243 if (!value.isEmpty()) {
245 return clientETag.sliced(1, clientETag.size() - 2) == etag ||
246 clientETag.
sliced(3, clientETag.size() - 4) == etag;
253 auto value =
header(
"If-None-Match");
254 if (!value.isEmpty()) {
256 return clientETag.sliced(1, clientETag.size() - 2) == etag ||
257 clientETag.
sliced(3, clientETag.size() - 4) == etag;
269 return header(
"Last-Modified");
298 return header(
"Connection");
308 return header(
"User-Agent");
318 int fragmentPos = uri.
indexOf(
'#');
319 if (fragmentPos != -1) {
334 setHeader(
"Proxy-Authenticate"_ba, value);
339 return header(
"Authorization");
346 int pos = auth.indexOf(
"Bearer ");
349 ret = auth.
mid(pos, auth.indexOf(
',', pos) - pos);
368 qCWarning(CUTELYST_CORE) <<
"Headers::Basic authorization user name can't contain ':'";
372 const QString result = username + u
':' + password;
380 return header(
"Proxy-Authorization");
395 if (
auto result = findHeaderConst(m_data, key); result != m_data.end()) {
396 return result->value;
408 if (
auto result = findHeaderConst(m_data, key); result != m_data.end()) {
409 return result->value;
422 for (
auto result = findHeaderConst(m_data, key); result != m_data.end(); ++result) {
423 ret.
append(result->value);
431 for (
auto result = findHeaderConst(m_data, key); result != m_data.end(); ++result) {
443 if (
auto result = std::find_if(m_data.begin(), m_data.end(), matchKey);
444 result != m_data.end()) {
445 result->value = value;
449 std::remove_if(result, m_data.end(), matchKey);
450 m_data.erase(begin, m_data.
cend());
463 m_data.push_back({key, value});
468 m_data.push_back({key, values.
join(
", ")});
479 auto result = findHeaderConst(m_data, key);
480 return result != m_data.end();
487 for (
const auto &
header : m_data) {
489 for (
const auto &key : ret) {
511 const auto otherData = other.data();
512 if (m_data.size() != otherData.size()) {
516 for (
const auto &myValue : m_data) {
517 if (!other.data().contains(myValue)) {
528 int pos = auth.
indexOf(
"Basic ");
531 ret = auth.
mid(pos, auth.indexOf(
',', pos) - pos);
540 const QByteArray authorization = decodeBasicAuth(auth);
541 if (!authorization.
isEmpty()) {
542 int pos = authorization.
indexOf(
':');
553QDebug operator<<(QDebug debug,
const Headers &headers)
555 const auto data = headers.
data();
558 for (
auto it = data.begin(); it != data.end(); ++it) {
559 debug <<
'(' << it->key +
'=' + it->value <<
')';
The Cutelyst namespace holds all public Cutelyst API.
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
bool endsWith(QByteArrayView bv) const const
QByteArray fromBase64(const QByteArray &base64, QByteArray::Base64Options options)
qsizetype indexOf(QByteArrayView bv, qsizetype from) const const
bool isEmpty() const const
QByteArray left(qsizetype len) &&
QByteArray mid(qsizetype pos, qsizetype len) &&
QByteArray number(double n, char format, int precision)
QByteArray sliced(qsizetype pos) &&
bool startsWith(QByteArrayView bv) const const
QByteArray toBase64(QByteArray::Base64Options options) const const
QByteArray toLower() const const
QByteArray join(QByteArrayView separator) const const
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
void setTimeSpec(Qt::TimeSpec spec)
bool autoInsertSpaces() const const
void setAutoInsertSpaces(bool b)
void append(QList< T > &&value)
QList< T >::const_iterator cend() const const
QDateTime toDateTime(const QString &string, QLocale::FormatType format, QCalendar cal, int baseYear) const const
QString toString(QDate date, QLocale::FormatType format) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString fromLatin1(QByteArrayView str)
QByteArray toLatin1() const const