Cutelyst  2.5.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();
36 
37 #ifdef Q_COMPILER_INITIALIZER_LISTS
38 
41  inline Headers(std::initializer_list<std::pair<QString,QString> > list)
42  {
43  for (std::initializer_list<std::pair<QString,QString> >::const_iterator it = list.begin(); it != list.end(); ++it)
44  pushHeader(it->first, it->second);
45  }
46 #endif
47 
53  QString contentDisposition() const;
54 
59  void setContentDisposition(const QString &contentDisposition);
60 
66  void setContentDispositionAttachment(const QString &filename = QString());
67 
72  QString contentEncoding() const;
73 
78  void setContentEncoding(const QString &encoding);
79 
86  QString contentType() const;
87 
92  void setContentType(const QString &contentType);
93 
97  QString contentTypeCharset() const;
98 
103  void setContentTypeCharset(const QString &charset);
104 
108  bool contentIsText() const;
109 
114  bool contentIsHtml() const;
115 
119  bool contentIsXHtml() const;
120 
124  bool contentIsXml() const;
125 
129  qint64 contentLength() const;
130 
134  void setContentLength(qint64 value);
135 
139  QString setDateWithDateTime(const QDateTime &date);
140 
144  QDateTime date() const;
145 
151  QString ifModifiedSince() const;
152 
160  QDateTime ifModifiedSinceDateTime() const;
161 
165  QString lastModified() const;
166 
170  void setLastModified(const QString &value);
171 
176  QString setLastModified(const QDateTime &lastModified);
177 
182  QString server() const;
183 
188  void setServer(const QString &value);
189 
194  QString connection() const;
195 
200  QString host() const;
201 
205  QString userAgent() const;
206 
210  QString referer() const;
211 
218  void setReferer(const QString &value);
219 
225  void setWwwAuthenticate(const QString &value);
226 
230  void setProxyAuthenticate(const QString &value);
231 
235  QString authorization() const;
236 
242  QString authorizationBasic() const;
243 
249  std::pair<QString, QString> authorizationBasicPair() const;
250 
256  QString setAuthorizationBasic(const QString &username, const QString &password);
257 
261  QString proxyAuthorization() const;
262 
268  QString proxyAuthorizationBasic() const;
269 
275  std::pair<QString, QString> proxyAuthorizationBasicPair() const;
276 
280  QString header(const QString &field) const;
281 
285  QString header(const QString &field, const QString &defaultValue) const;
286 
290  void setHeader(const QString &field, const QString &value);
291 
295  void setHeader(const QString &field, const QStringList &values);
296 
300  void pushHeader(const QString &field, const QString &value);
301 
309  inline void pushRawHeader(const QString &field, const QString &value);
310 
314  void pushHeader(const QString &field, const QStringList &values);
315 
319  void removeHeader(const QString &field);
320 
324  inline void clear() {
325  m_data.clear();
326  }
327 
331  inline QHash<QString, QString> data() const {
332  return m_data;
333  }
334 
338  bool contains(const QString &field);
339 
343  QString &operator[](const QString &key);
344 
348  const QString operator[](const QString &key) const;
349 
353  inline Headers &operator=(const Headers &other)
354  {
355  m_data = other.m_data;
356  return *this;
357  }
358 
362  inline bool operator==(const Headers &other) const {
363  return m_data == other.m_data;
364  }
365 
369  inline bool operator!=(const Headers &other) const {
370  return m_data != other.m_data;
371  }
372 
376  inline operator QVariant() const {
377  return QVariant::fromValue(m_data);
378  }
379 
380 private:
381  QHash<QString, QString> m_data;
382 };
383 
384 void Headers::pushRawHeader(const QString &field, const QString &value) {
385  m_data.insertMulti(field, value);
386 }
387 
388 }
389 
390 Q_DECLARE_METATYPE(Cutelyst::Headers)
391 
392 QDebug CUTELYST_LIBRARY operator<<(QDebug dbg, const Cutelyst::Headers &headers);
393 
394 #endif // HEADERS_H
void pushRawHeader(const QString &field, const QString &value)
Definition: headers.h:384
QHash< QString, QString > data() const
Definition: headers.h:331
bool operator!=(const Headers &other) const
Definition: headers.h:369
bool operator==(const Headers &other) const
Definition: headers.h:362
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
Headers(std::initializer_list< std::pair< QString, QString > > list)
Definition: headers.h:41
Headers & operator=(const Headers &other)
Definition: headers.h:353