Cutelyst  1.5.0
headers.h
1 /*
2  * Copyright (C) 2014-2016 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 Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifndef HEADERS_H
20 #define HEADERS_H
21 
22 #include <QtCore/QVariant>
23 #include <QtCore/QDateTime>
24 #include <QtCore/QMetaType>
25 
26 #include <Cutelyst/cutelyst_global.h>
27 
28 namespace Cutelyst {
29 
30 class CUTELYST_LIBRARY Headers
31 {
32 public:
33  Headers();
34 #ifdef Q_COMPILER_INITIALIZER_LISTS
35  inline Headers(std::initializer_list<std::pair<QString,QString> > list)
36  {
37  for (std::initializer_list<std::pair<QString,QString> >::const_iterator it = list.begin(); it != list.end(); ++it)
38  pushHeader(it->first, it->second);
39  }
40 #endif
41 
42  QString contentEncoding() const;
43 
44  void setContentEncoding(const QString &encoding);
45 
52  QString contentType() const;
53 
58  void setContentType(const QString &contentType);
59 
63  QString contentTypeCharset() const;
64 
69  void setContentTypeCharset(const QString &charset);
70 
74  bool contentIsText() const;
75 
80  bool contentIsHtml() const;
81 
85  bool contentIsXHtml() const;
86 
90  bool contentIsXml() const;
91 
95  qint64 contentLength() const;
96 
100  void setContentLength(qint64 value);
101 
105  QString setDateWithDateTime(const QDateTime &date);
106 
110  QDateTime date() const;
111 
117  QString ifModifiedSince() const;
118 
126  QDateTime ifModifiedSinceDateTime() const;
127 
131  QString lastModified() const;
132 
136  void setLastModified(const QString &value);
137 
142  QString setLastModified(const QDateTime &lastModified);
143 
148  QString server() const;
149 
154  void setServer(const QString &value);
155 
156  QString connection() const;
157 
158  QString host() const;
159 
160  QString userAgent() const;
161 
162  QString referer() const;
163 
170  void setReferer(const QString &value);
171 
177  void setWwwAuthenticate(const QString &value);
178 
182  void setProxyAuthenticate(const QString &value);
183 
187  QString authorization() const;
188 
194  QString authorizationBasic() const;
195 
201  QPair<QString, QString> authorizationBasicPair() const;
202 
208  QString setAuthorizationBasic(const QString &username, const QString &password);
209 
215  QHash<QString, QString> authorizationDigest() const;
216 
220  QString proxyAuthorization() const;
221 
227  QString proxyAuthorizationBasic() const;
228 
234  QPair<QString, QString> proxyAuthorizationBasicPair() const;
235 
236  QString header(const QString &field) const;
237 
238  QString header(const QString &field, const QString &defaultValue) const;
239 
243  void setHeader(const QString &field, const QString &value);
244 
245  void setHeader(const QString &field, const QStringList &values);
246 
247  void pushHeader(const QString &field, const QString &value);
248 
256  inline void pushRawHeader(const QString &field, const QString &value);
257 
258  void pushHeader(const QString &field, const QStringList &values);
259 
260  void removeHeader(const QString &field);
261 
262  inline void clear() {
263  m_data.clear();
264  }
265 
266  inline QHash<QString, QString> data() const {
267  return m_data;
268  }
269 
270  bool contains(const QString &field);
271 
272  QString &operator[](const QString &key);
273  const QString operator[](const QString &key) const;
274  inline Headers &operator=(const Headers &other)
275  {
276  m_data = other.m_data;
277  return *this;
278  }
279  inline bool operator==(const Headers &other) const {
280  return m_data == other.m_data;
281  }
282  inline bool operator!=(const Headers &other) const {
283  return m_data != other.m_data;
284  }
285 
286  inline operator QVariant() const {
287  return QVariant::fromValue(m_data);
288  }
289 
290 private:
291  QHash<QString, QString> m_data;
292 };
293 
294 void Headers::pushRawHeader(const QString &field, const QString &value) {
295  m_data.insertMulti(field, value);
296 }
297 
298 }
299 
300 Q_DECLARE_METATYPE(Cutelyst::Headers)
301 
302 #endif // HEADERS_H
void pushRawHeader(const QString &field, const QString &value)
Definition: headers.h:294
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7