10 #include <QStringList> 25 return std::find_if(headers.cbegin(), headers.cend(), matchKey);
30 : m_data(other.m_data)
36 return header(
"Content-Disposition");
41 setHeader(
"Cache-Control"_ba, value);
46 setHeader(
"Content-Disposition"_ba, contentDisposition);
52 setContentDisposition(
"attachment");
54 setContentDisposition(
"attachment; filename=\"" + filename +
'"');
60 return header(
"Content-Encoding");
65 setHeader(
"Content-Encoding"_ba, encoding);
79 setHeader(
"Content-Type"_ba, contentType);
85 const QByteArray contentType = header(
"Content-Type");
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())) {
101 setContentType(
"charset=" + charset);
106 int pos = contentType.
indexOf(
"charset=", 0);
108 int endPos = contentType.
indexOf(
';', pos);
113 removeHeader(
"Content-Type");
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);
127 setContentType(contentType);
132 return header(
"Content-Type").startsWith(
"text/");
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();
184 setHeader(
"Date"_ba, dt);
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()) {
234 .
toString(lastModified.
toUTC(), u
"ddd, dd MMM yyyy hh:mm:ss 'GMT")
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;
264 setHeader(
"ETag"_ba,
'"' + etag +
'"');
269 return header(
"Last-Modified");
274 setHeader(
"Last-Modified"_ba, value);
282 setLastModified(dt.toLatin1());
288 return header(
"Server");
293 setHeader(
"Server"_ba, value);
298 return header(
"Connection");
303 return header(
"Host");
308 return header(
"User-Agent");
313 return header(
"Referer");
318 int fragmentPos = uri.
indexOf(
'#');
319 if (fragmentPos != -1) {
321 setHeader(
"Referer"_ba, uri.
mid(0, fragmentPos));
323 setHeader(
"Referer"_ba, uri);
329 setHeader(
"Www-Authenticate"_ba, value);
334 setHeader(
"Proxy-Authenticate"_ba, value);
339 return header(
"Authorization");
345 auto auth = authorization();
346 int pos = auth.indexOf(
"Bearer ");
349 ret = auth.
mid(pos, auth.indexOf(
',', pos) - pos);
356 return decodeBasicAuth(authorization());
361 return decodeBasicAuthPair(authorization());
368 qCWarning(CUTELYST_CORE) <<
"Headers::Basic authorization user name can't contain ':'";
372 const QString result = username + u
':' + password;
374 setHeader(
"Authorization"_ba, ret);
380 return header(
"Proxy-Authorization");
385 return decodeBasicAuth(proxyAuthorization());
390 return decodeBasicAuthPair(proxyAuthorization());
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);
458 setHeader(field, values.
join(
", "));
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(
':');
555 const auto data = headers.
data();
558 for (
auto it = data.begin(); it != data.end(); ++it) {
559 debug <<
'(' << it->key +
'=' + it->value <<
')';
void setTimeSpec(Qt::TimeSpec spec)
void setAutoInsertSpaces(bool b)
QDateTime toUTC() const const
QByteArray trimmed() const const
qsizetype lastIndexOf(QByteArrayView bv) const const
iterator erase(const_iterator begin, const_iterator end)
QByteArray toUpper() const const
bool isEmpty() const const
QDateTime toDateTime(const QString &string, FormatType format) const const
qsizetype length() const const
QString toString(QDate date, FormatType format) const const
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
QByteArray join(QByteArrayView separator) const const
qsizetype indexOf(QByteArrayView bv, qsizetype from) const const
QByteArray number(double n, char format, int precision)
QByteArray & replace(QByteArrayView before, QByteArrayView after)
The Cutelyst namespace holds all public Cutelyst API.
QByteArray sliced(qsizetype pos) const const
QByteArray mid(qsizetype pos, qsizetype len) const const
QByteArray & append(QByteArrayView data)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString fromLatin1(QByteArrayView str)
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
QByteArray left(qsizetype len) const const
const_iterator cend() const const
QByteArray toLatin1() const const
QByteArray fromBase64(const QByteArray &base64, Base64Options options)
void append(QList< T > &&value)
bool autoInsertSpaces() const const
QByteArray toBase64(Base64Options options) const const
QByteArray & remove(qsizetype pos, qsizetype len)
bool endsWith(QByteArrayView bv) const const