cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
headers.h
1/*
2 * SPDX-FileCopyrightText: (C) 2014-2022 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#pragma once
6
7#include <Cutelyst/cutelyst_global.h>
8
9#include <QtCore/QDateTime>
10#include <QtCore/QMetaType>
11#include <QtCore/QVariant>
12
13namespace Cutelyst {
14
23class CUTELYST_LIBRARY Headers
24{
25public:
27 QByteArray key;
28 QByteArray value;
29
30 inline bool operator==(const HeaderKeyValue &other) const
31 {
32 return (key.compare(other.key, Qt::CaseInsensitive) == 0) && value == other.value;
33 }
34 };
35
39 Headers() noexcept = default;
40
44 Headers(const Headers &other) noexcept;
45
49 inline Headers(std::initializer_list<std::pair<QByteArray, QByteArray>> list)
50 {
51 for (std::initializer_list<std::pair<QByteArray, QByteArray>>::const_iterator it =
52 list.begin();
53 it != list.end();
54 ++it)
55 m_data.emplace_back(HeaderKeyValue{it->first, it->second});
56 }
57
65 [[nodiscard]] QByteArray contentDisposition() const noexcept;
66
70 void setCacheControl(const QByteArray &value);
71
76 void setContentDisposition(const QByteArray &contentDisposition);
77
83 void setContentDispositionAttachment(const QByteArray &filename = {});
84
90 [[nodiscard]] QByteArray contentEncoding() const noexcept;
91
96 void setContentEncoding(const QByteArray &encoding);
97
105 [[nodiscard]] QByteArray contentType() const;
106
111 void setContentType(const QByteArray &contentType);
112
117 [[nodiscard]] QByteArray contentTypeCharset() const;
118
123 void setContentTypeCharset(const QByteArray &charset);
124
128 [[nodiscard]] bool contentIsText() const;
129
134 [[nodiscard]] bool contentIsHtml() const;
135
139 [[nodiscard]] bool contentIsXHtml() const;
140
144 [[nodiscard]] bool contentIsXml() const;
145
149 [[nodiscard]] bool contentIsJson() const;
150
155 [[nodiscard]] qint64 contentLength() const;
156
161 void setContentLength(qint64 value);
162
166 QByteArray setDateWithDateTime(const QDateTime &date);
167
171 [[nodiscard]] QDateTime date() const;
172
178 [[nodiscard]] QByteArray ifModifiedSince() const noexcept;
179
187 [[nodiscard]] QDateTime ifModifiedSinceDateTime() const;
188
193 [[nodiscard]] bool ifModifiedSince(const QDateTime &lastModified) const;
194
204 [[nodiscard]] bool ifMatch(const QByteArray &etag) const;
205
214 [[nodiscard]] bool ifNoneMatch(const QByteArray &etag) const;
215
221 void setETag(const QByteArray &etag);
222
226 [[nodiscard]] QByteArray lastModified() const noexcept;
227
231 void setLastModified(const QByteArray &value);
232
237 QString setLastModified(const QDateTime &lastModified);
238
243 [[nodiscard]] QByteArray server() const noexcept;
244
249 void setServer(const QByteArray &value);
250
255 [[nodiscard]] QByteArray connection() const noexcept;
256
262 [[nodiscard]] QByteArray host() const noexcept;
263
268 [[nodiscard]] QByteArray userAgent() const noexcept;
269
274 [[nodiscard]] QByteArray referer() const noexcept;
275
282 void setReferer(const QByteArray &value);
283
289 void setWwwAuthenticate(const QByteArray &value);
290
294 void setProxyAuthenticate(const QByteArray &value);
295
299 [[nodiscard]] QByteArray authorization() const noexcept;
300
304 [[nodiscard]] QByteArray authorizationBearer() const;
305
311 [[nodiscard]] QByteArray authorizationBasic() const;
312
314 QString user;
315 QString password;
316 };
317
323 [[nodiscard]] Authorization authorizationBasicObject() const;
324
330 QByteArray setAuthorizationBasic(const QString &username, const QString &password);
331
336 [[nodiscard]] QByteArray proxyAuthorization() const noexcept;
337
343 [[nodiscard]] QByteArray proxyAuthorizationBasic() const;
344
350 [[nodiscard]] Authorization proxyAuthorizationBasicObject() const;
351
355 [[nodiscard]] QByteArray header(QByteArrayView key) const noexcept;
356
361 [[nodiscard]] QString headerAsString(QByteArrayView key) const;
362
366 [[nodiscard]] QByteArray header(QByteArrayView key,
367 const QByteArray &defaultValue) const noexcept;
368
373 [[nodiscard]] QString headerAsString(QByteArrayView key, const QByteArray &defaultValue) const;
374
378 [[nodiscard]] QByteArrayList headers(QByteArrayView key) const;
379
384 [[nodiscard]] QStringList headersAsStrings(QByteArrayView key) const;
385
389 void setHeader(const QByteArray &key, const QByteArray &value);
390
394 void setHeader(const QByteArray &field, const QByteArrayList &values);
395
399 void pushHeader(const QByteArray &key, const QByteArray &value);
400
404 void pushHeader(const QByteArray &key, const QByteArrayList &values);
405
409 void removeHeader(QByteArrayView key);
410
414 inline void clear() { m_data.clear(); }
415
419 [[nodiscard]] inline QVector<HeaderKeyValue> data() const { return m_data; }
420
424 [[nodiscard]] bool contains(QByteArrayView key) const noexcept;
425
426 [[nodiscard]] QByteArrayList keys() const;
427
431 QByteArray operator[](QByteArrayView key) const noexcept;
432
436 inline Headers &operator=(const Headers &other) noexcept
437 {
438 m_data = other.m_data;
439 return *this;
440 }
441
445 bool operator==(const Headers &other) const noexcept;
446
447private:
449};
450
451} // namespace Cutelyst
452
453Q_DECLARE_METATYPE(Cutelyst::Headers)
454
455QDebug CUTELYST_LIBRARY operator<<(QDebug dbg, const Cutelyst::Headers &headers);
Container for HTTP headers.
Definition headers.h:24
QVector< HeaderKeyValue > data() const
Definition headers.h:419
Headers() noexcept=default
Headers & operator=(const Headers &other) noexcept
Definition headers.h:436
The Cutelyst namespace holds all public Cutelyst API.
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
void clear()
CaseInsensitive