Enable customizing the save statistics time interval
[qBittorrent.git] / src / base / http / types.h
blob8641003e84ac026dcaf1dd95fb08c916f9fa9799
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2018 Mike Tzou (Chocobo1)
4 * Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
30 #pragma once
32 #include <QHostAddress>
33 #include <QList>
34 #include <QString>
36 #include "base/global.h"
38 namespace Http
40 inline const QString METHOD_GET = u"GET"_s;
41 inline const QString METHOD_POST = u"POST"_s;
43 inline const QString HEADER_CACHE_CONTROL = u"cache-control"_s;
44 inline const QString HEADER_CONNECTION = u"connection"_s;
45 inline const QString HEADER_CONTENT_DISPOSITION = u"content-disposition"_s;
46 inline const QString HEADER_CONTENT_ENCODING = u"content-encoding"_s;
47 inline const QString HEADER_CONTENT_LENGTH = u"content-length"_s;
48 inline const QString HEADER_CONTENT_SECURITY_POLICY = u"content-security-policy"_s;
49 inline const QString HEADER_CONTENT_TYPE = u"content-type"_s;
50 inline const QString HEADER_CROSS_ORIGIN_OPENER_POLICY = u"cross-origin-opener-policy"_s;
51 inline const QString HEADER_DATE = u"date"_s;
52 inline const QString HEADER_HOST = u"host"_s;
53 inline const QString HEADER_ORIGIN = u"origin"_s;
54 inline const QString HEADER_REFERER = u"referer"_s;
55 inline const QString HEADER_REFERRER_POLICY = u"referrer-policy"_s;
56 inline const QString HEADER_SET_COOKIE = u"set-cookie"_s;
57 inline const QString HEADER_X_CONTENT_TYPE_OPTIONS = u"x-content-type-options"_s;
58 inline const QString HEADER_X_FORWARDED_FOR = u"x-forwarded-for"_s;
59 inline const QString HEADER_X_FORWARDED_HOST = u"x-forwarded-host"_s;
60 inline const QString HEADER_X_FORWARDED_PROTO = u"X-forwarded-proto"_s;
61 inline const QString HEADER_X_FRAME_OPTIONS = u"x-frame-options"_s;
62 inline const QString HEADER_X_XSS_PROTECTION = u"x-xss-protection"_s;
64 inline const QString HEADER_REQUEST_METHOD_GET = u"GET"_s;
65 inline const QString HEADER_REQUEST_METHOD_HEAD = u"HEAD"_s;
66 inline const QString HEADER_REQUEST_METHOD_POST = u"POST"_s;
68 inline const QString CONTENT_TYPE_HTML = u"text/html"_s;
69 inline const QString CONTENT_TYPE_CSS = u"text/css"_s;
70 inline const QString CONTENT_TYPE_TXT = u"text/plain; charset=UTF-8"_s;
71 inline const QString CONTENT_TYPE_JS = u"application/javascript"_s;
72 inline const QString CONTENT_TYPE_JSON = u"application/json"_s;
73 inline const QString CONTENT_TYPE_GIF = u"image/gif"_s;
74 inline const QString CONTENT_TYPE_PNG = u"image/png"_s;
75 inline const QString CONTENT_TYPE_FORM_ENCODED = u"application/x-www-form-urlencoded"_s;
76 inline const QString CONTENT_TYPE_FORM_DATA = u"multipart/form-data"_s;
78 // portability: "\r\n" doesn't guarantee mapping to the correct symbol
79 inline const char CRLF[] = {0x0D, 0x0A, '\0'};
81 struct Environment
83 QHostAddress localAddress;
84 quint16 localPort = 0;
86 QHostAddress clientAddress;
87 quint16 clientPort = 0;
90 struct UploadedFile
92 QString filename;
93 QString type; // MIME type
94 QByteArray data;
97 struct Header
99 QString name;
100 QString value;
103 using HeaderMap = QMap<QString, QString>; // <Header name, Header value>
105 struct Request
107 QString version;
108 QString method;
109 QString path;
110 HeaderMap headers;
111 QHash<QString, QByteArray> query;
112 QHash<QString, QString> posts;
113 QList<UploadedFile> files;
116 struct ResponseStatus
118 uint code;
119 QString text;
122 struct Response
124 ResponseStatus status;
125 HeaderMap headers;
126 QByteArray content;
128 Response(uint code = 200, const QString &text = u"OK"_s)
129 : status {code, text}