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);
87 int pos = _contentType.
indexOf(
"charset=", 0);
89 int endPos = _contentType.
indexOf(u
';', pos);
99 auto result = findHeaderConst(m_data,
"Content-Type");
100 if (result == m_data.end() || (result->value.isEmpty() && !charset.
isEmpty())) {
106 int pos = _contentType.
indexOf(
"charset=", 0);
108 int endPos = _contentType.
indexOf(
';', pos);
116 _contentType.
remove(lastPos, _contentType.
length() - lastPos);
119 _contentType.
replace(pos + 8, _contentType.
length() - pos + 8, charset);
122 _contentType.
replace(pos + 8, endPos, charset);
124 }
else if (!charset.
isEmpty()) {
125 _contentType.
append(
"; charset=" + charset);
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;
416 if (
auto result = findHeaderConst(m_data, key); result != m_data.end()) {
425 for (
auto result = findHeaderConst(m_data, key); result != m_data.end(); ++result) {
426 ret.
append(result->value);
434 for (
auto result = findHeaderConst(m_data, key); result != m_data.end(); ++result) {
446 if (
auto result = std::find_if(m_data.begin(), m_data.end(), matchKey);
447 result != m_data.end()) {
448 result->value = value;
452 std::remove_if(result, m_data.end(), matchKey);
453 m_data.erase(begin, m_data.cend());
483 auto result = findHeaderConst(m_data, key);
484 return result != m_data.end();
491 for (
const auto &_header : m_data) {
492 const bool exists = std::ranges::any_of(ret, [&](
const QByteArray &key) {
511 const auto otherData = other.data();
512 if (m_data.size() != otherData.size()) {
516 return std::ranges::all_of(
517 m_data, [otherData](
const auto &myValue) {
return otherData.contains(myValue); });
523 int pos = auth.
indexOf(
"Basic ");
526 ret = auth.
mid(pos, auth.
indexOf(
',', pos) - pos);
535 const QByteArray authorization = decodeBasicAuth(auth);
536 if (!authorization.
isEmpty()) {
537 int pos = authorization.
indexOf(
':');
550 const auto data = headers.
data();
553 for (
auto it = data.begin(); it != data.end(); ++it) {
554 debug <<
'(' << it->key +
'=' + it->value <<
')';
The Cutelyst namespace holds all public Cutelyst API.
int compare(QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs)
QAnyStringView sliced(qsizetype pos) const const
QByteArray & append(QByteArrayView data)
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
qsizetype lastIndexOf(QByteArrayView bv) const const
QByteArray left(qsizetype len) const const
qsizetype length() const const
QByteArray mid(qsizetype pos, qsizetype len) const const
QByteArray number(double n, char format, int precision)
QByteArray & remove(qsizetype pos, qsizetype len)
QByteArray & replace(QByteArrayView before, QByteArrayView after)
bool startsWith(QByteArrayView bv) const const
QByteArray toBase64(QByteArray::Base64Options options) const const
QByteArray toLower() const const
QByteArray toUpper() const const
QByteArray trimmed() const const
QByteArray join(QByteArrayView separator) const const
void setTimeSpec(Qt::TimeSpec spec)
QDateTime toUTC() const const
bool autoInsertSpaces() const const
void setAutoInsertSpaces(bool b)
void append(QList::parameter_type value)
QDateTime toDateTime(const QString &string, QLocale::FormatType format) 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