Cutelyst  2.13.0
headers.h
1 /*
2  * Copyright (C) 2014-2018 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
43 
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 
291  QString authorizationBasic() const;
292 
298  std::pair<QString, QString> authorizationBasicPair() const;
299 
305  QString setAuthorizationBasic(const QString &username, const QString &password);
306 
310  QString proxyAuthorization() const;
311 
317  QString proxyAuthorizationBasic() const;
318 
324  std::pair<QString, QString> proxyAuthorizationBasicPair() const;
325 
329  QString header(const QString &field) const;
330 
334  QString header(const QString &field, const QString &defaultValue) const;
335 
339  void setHeader(const QString &field, const QString &value);
340 
344  void setHeader(const QString &field, const QStringList &values);
345 
349  void pushHeader(const QString &field, const QString &value);
350 
358  inline void pushRawHeader(const QString &field, const QString &value);
359 
363  void pushHeader(const QString &field, const QStringList &values);
364 
368  void removeHeader(const QString &field);
369 
373  inline void clear() {
374  m_data.clear();
375  }
376 
380  inline QHash<QString, QString> data() const {
381  return m_data;
382  }
383 
387  bool contains(const QString &field);
388 
392  QString &operator[](const QString &key);
393 
397  const QString operator[](const QString &key) const;
398 
402  inline Headers &operator=(const Headers &other)
403  {
404  m_data = other.m_data;
405  return *this;
406  }
407 
411  inline bool operator==(const Headers &other) const {
412  return m_data == other.m_data;
413  }
414 
418  inline bool operator!=(const Headers &other) const {
419  return m_data != other.m_data;
420  }
421 
425  inline operator QVariant() const {
426  return QVariant::fromValue(m_data);
427  }
428 
429 private:
430  QHash<QString, QString> m_data;
431 };
432 
433 void Headers::pushRawHeader(const QString &field, const QString &value) {
434  m_data.insertMulti(field, value);
435 }
436 
437 }
438 
439 Q_DECLARE_METATYPE(Cutelyst::Headers)
440 
441 QDebug CUTELYST_LIBRARY operator<<(QDebug dbg, const Cutelyst::Headers &headers);
442 
443 #endif // HEADERS_H
Cutelyst::Headers::clear
void clear()
Definition: headers.h:373
Cutelyst::Headers::Headers
Headers(std::initializer_list< std::pair< QString, QString > > list)
Definition: headers.h:46
Cutelyst::Headers::pushRawHeader
void pushRawHeader(const QString &field, const QString &value)
Definition: headers.h:433
Cutelyst::Headers::data
QHash< QString, QString > data() const
Definition: headers.h:380
Cutelyst::Headers
Definition: headers.h:29
Cutelyst::Headers::operator!=
bool operator!=(const Headers &other) const
Definition: headers.h:418
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
Cutelyst::Headers::operator==
bool operator==(const Headers &other) const
Definition: headers.h:411
Cutelyst::Headers::operator=
Headers & operator=(const Headers &other)
Definition: headers.h:402