Cutelyst  1.8.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:
36  Headers();
37 
38 #ifdef Q_COMPILER_INITIALIZER_LISTS
39 
42  inline Headers(std::initializer_list<std::pair<QString,QString> > list)
43  {
44  for (std::initializer_list<std::pair<QString,QString> >::const_iterator it = list.begin(); it != list.end(); ++it)
45  pushHeader(it->first, it->second);
46  }
47 #endif
48 
54  QString contentDisposition() const;
55 
60  void setContentDisposition(const QString &contentDisposition);
61 
67  void setContentDispositionAttachment(const QString &filename = QString());
68 
73  QString contentEncoding() const;
74 
79  void setContentEncoding(const QString &encoding);
80 
87  QString contentType() const;
88 
93  void setContentType(const QString &contentType);
94 
98  QString contentTypeCharset() const;
99 
104  void setContentTypeCharset(const QString &charset);
105 
109  bool contentIsText() const;
110 
115  bool contentIsHtml() const;
116 
120  bool contentIsXHtml() const;
121 
125  bool contentIsXml() const;
126 
130  qint64 contentLength() const;
131 
135  void setContentLength(qint64 value);
136 
140  QString setDateWithDateTime(const QDateTime &date);
141 
145  QDateTime date() const;
146 
152  QString ifModifiedSince() const;
153 
161  QDateTime ifModifiedSinceDateTime() const;
162 
166  QString lastModified() const;
167 
171  void setLastModified(const QString &value);
172 
177  QString setLastModified(const QDateTime &lastModified);
178 
183  QString server() const;
184 
189  void setServer(const QString &value);
190 
195  QString connection() const;
196 
201  QString host() const;
202 
206  QString userAgent() const;
207 
211  QString referer() const;
212 
219  void setReferer(const QString &value);
220 
226  void setWwwAuthenticate(const QString &value);
227 
231  void setProxyAuthenticate(const QString &value);
232 
236  QString authorization() const;
237 
243  QString authorizationBasic() const;
244 
250  QPair<QString, QString> authorizationBasicPair() const;
251 
257  QString setAuthorizationBasic(const QString &username, const QString &password);
258 
264  QHash<QString, QString> authorizationDigest() const;
265 
269  QString proxyAuthorization() const;
270 
276  QString proxyAuthorizationBasic() const;
277 
283  QPair<QString, QString> proxyAuthorizationBasicPair() const;
284 
288  QString header(const QString &field) const;
289 
293  QString header(const QString &field, const QString &defaultValue) const;
294 
298  void setHeader(const QString &field, const QString &value);
299 
303  void setHeader(const QString &field, const QStringList &values);
304 
308  void pushHeader(const QString &field, const QString &value);
309 
317  inline void pushRawHeader(const QString &field, const QString &value);
318 
322  void pushHeader(const QString &field, const QStringList &values);
323 
327  void removeHeader(const QString &field);
328 
332  inline void clear() {
333  m_data.clear();
334  }
335 
339  inline QHash<QString, QString> data() const {
340  return m_data;
341  }
342 
346  bool contains(const QString &field);
347 
351  QString &operator[](const QString &key);
352 
356  const QString operator[](const QString &key) const;
357 
361  inline Headers &operator=(const Headers &other)
362  {
363  m_data = other.m_data;
364  return *this;
365  }
366 
370  inline bool operator==(const Headers &other) const {
371  return m_data == other.m_data;
372  }
373 
377  inline bool operator!=(const Headers &other) const {
378  return m_data != other.m_data;
379  }
380 
384  inline operator QVariant() const {
385  return QVariant::fromValue(m_data);
386  }
387 
388 private:
389  QHash<QString, QString> m_data;
390 };
391 
392 void Headers::pushRawHeader(const QString &field, const QString &value) {
393  m_data.insertMulti(field, value);
394 }
395 
396 }
397 
398 Q_DECLARE_METATYPE(Cutelyst::Headers)
399 
400 #endif // HEADERS_H
void pushRawHeader(const QString &field, const QString &value)
Definition: headers.h:392
bool operator!=(const Headers &other) const
Definition: headers.h:377
bool operator==(const Headers &other) const
Definition: headers.h:370
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
QHash< QString, QString > data() const
Definition: headers.h:339
Headers(std::initializer_list< std::pair< QString, QString > > list)
Definition: headers.h:42
Headers & operator=(const Headers &other)
Definition: headers.h:361