Cutelyst  3.1.0
headers.h
1 /*
2  * Copyright (C) 2014-2021 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef HEADERS_H
19 #define HEADERS_H
20 
21 #include <QtCore/QVariant>
22 #include <QtCore/QDateTime>
23 #include <QtCore/QMetaType>
24 
25 #include <Cutelyst/cutelyst_global.h>
26 
27 namespace Cutelyst {
28 
29 class CUTELYST_LIBRARY Headers
30 {
31 public:
35  Headers() = default;
36 
40  Headers(const Headers &other);
41 
42 #ifdef Q_COMPILER_INITIALIZER_LISTS
46  inline Headers(std::initializer_list<std::pair<QString,QString> > list)
47  {
48  for (std::initializer_list<std::pair<QString,QString> >::const_iterator it = list.begin(); it != list.end(); ++it)
49  pushHeader(it->first, it->second);
50  }
51 #endif
52 
58  QString contentDisposition() const;
59 
63  void setCacheControl(const QString &value);
64 
69  void setContentDisposition(const QString &contentDisposition);
70 
76  void setContentDispositionAttachment(const QString &filename = QString());
77 
82  QString contentEncoding() const;
83 
88  void setContentEncoding(const QString &encoding);
89 
96  QString contentType() const;
97 
102  void setContentType(const QString &contentType);
103 
107  QString contentTypeCharset() const;
108 
113  void setContentTypeCharset(const QString &charset);
114 
118  bool contentIsText() const;
119 
124  bool contentIsHtml() const;
125 
129  bool contentIsXHtml() const;
130 
134  bool contentIsXml() const;
135 
139  bool contentIsJson() const;
140 
144  qint64 contentLength() const;
145 
149  void setContentLength(qint64 value);
150 
154  QString setDateWithDateTime(const QDateTime &date);
155 
159  QDateTime date() const;
160 
166  QString ifModifiedSince() const;
167 
175  QDateTime ifModifiedSinceDateTime() const;
176 
181  bool ifModifiedSince(const QDateTime &lastModified) const;
182 
192  bool ifMatch(const QString &etag) const;
193 
202  bool ifNoneMatch(const QString &etag) const;
203 
209  void setETag(const QString &etag);
210 
214  QString lastModified() const;
215 
219  void setLastModified(const QString &value);
220 
225  QString setLastModified(const QDateTime &lastModified);
226 
231  QString server() const;
232 
237  void setServer(const QString &value);
238 
243  QString connection() const;
244 
249  QString host() const;
250 
254  QString userAgent() const;
255 
259  QString referer() const;
260 
267  void setReferer(const QString &value);
268 
274  void setWwwAuthenticate(const QString &value);
275 
279  void setProxyAuthenticate(const QString &value);
280 
284  QString authorization() const;
285 
289  QString authorizationBearer() const;
290 
296  QString authorizationBasic() const;
297 
298  struct Authorization {
299  QString user;
300  QString password;
301  };
302 
308  Authorization authorizationBasicObject() const;
309 
315  QString setAuthorizationBasic(const QString &username, const QString &password);
316 
320  QString proxyAuthorization() const;
321 
327  QString proxyAuthorizationBasic() const;
328 
334  Authorization proxyAuthorizationBasicObject() const;
335 
339  QString header(const QString &field) const;
340 
344  QString header(const QString &field, const QString &defaultValue) const;
345 
349  void setHeader(const QString &field, const QString &value);
350 
354  void setHeader(const QString &field, const QStringList &values);
355 
359  void pushHeader(const QString &field, const QString &value);
360 
368  inline void pushRawHeader(const QString &field, const QString &value);
369 
373  void pushHeader(const QString &field, const QStringList &values);
374 
378  void removeHeader(const QString &field);
379 
383  inline void clear() {
384  m_data.clear();
385  }
386 
391  return m_data;
392  }
393 
397  bool contains(const QString &field);
398 
402  QString operator[](const QString &key) const;
403 
407  inline Headers &operator=(const Headers &other)
408  {
409  m_data = other.m_data;
410  return *this;
411  }
412 
416  inline bool operator==(const Headers &other) const {
417  return m_data == other.m_data;
418  }
419 
423  inline bool operator!=(const Headers &other) const {
424  return m_data != other.m_data;
425  }
426 
427 private:
429 };
430 
431 void Headers::pushRawHeader(const QString &field, const QString &value) {
432  m_data.insert(field, value);
433 }
434 
435 }
436 
437 Q_DECLARE_METATYPE(Cutelyst::Headers)
438 
439 QDebug CUTELYST_LIBRARY operator<<(QDebug dbg, const Cutelyst::Headers &headers);
440 
441 #endif // HEADERS_H
bool operator!=(const Headers &other) const
Definition: headers.h:423
bool operator==(const Headers &other) const
Definition: headers.h:416
void pushRawHeader(const QString &field, const QString &value)
Definition: headers.h:431
QMultiHash< QString, QString > data() const
Definition: headers.h:390
Headers & operator=(const Headers &other)
Definition: headers.h:407
Headers(std::initializer_list< std::pair< QString, QString > > list)
Definition: headers.h:46
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8
typename QHash< Key, T >::iterator insert(const Key &key, const T &value)