Fine tune translations loading for Chinese locales
[qBittorrent.git] / src / base / http / types.h
blob41b2b8bf523f6289c8a83e48e1caf0fce403a0f0
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 <QString>
34 #include <QVector>
36 #include "base/global.h"
38 namespace Http
40 inline const QString METHOD_GET = u"GET"_qs;
41 inline const QString METHOD_POST = u"POST"_qs;
43 inline const QString HEADER_CACHE_CONTROL = u"cache-control"_qs;
44 inline const QString HEADER_CONNECTION = u"connection"_qs;
45 inline const QString HEADER_CONTENT_DISPOSITION = u"content-disposition"_qs;
46 inline const QString HEADER_CONTENT_ENCODING = u"content-encoding"_qs;
47 inline const QString HEADER_CONTENT_LENGTH = u"content-length"_qs;
48 inline const QString HEADER_CONTENT_SECURITY_POLICY = u"content-security-policy"_qs;
49 inline const QString HEADER_CONTENT_TYPE = u"content-type"_qs;
50 inline const QString HEADER_DATE = u"date"_qs;
51 inline const QString HEADER_HOST = u"host"_qs;
52 inline const QString HEADER_ORIGIN = u"origin"_qs;
53 inline const QString HEADER_REFERER = u"referer"_qs;
54 inline const QString HEADER_REFERRER_POLICY = u"referrer-policy"_qs;
55 inline const QString HEADER_SET_COOKIE = u"set-cookie"_qs;
56 inline const QString HEADER_X_CONTENT_TYPE_OPTIONS = u"x-content-type-options"_qs;
57 inline const QString HEADER_X_FORWARDED_FOR = u"x-forwarded-for"_qs;
58 inline const QString HEADER_X_FORWARDED_HOST = u"x-forwarded-host"_qs;
59 inline const QString HEADER_X_FRAME_OPTIONS = u"x-frame-options"_qs;
60 inline const QString HEADER_X_XSS_PROTECTION = u"x-xss-protection"_qs;
62 inline const QString HEADER_REQUEST_METHOD_GET = u"GET"_qs;
63 inline const QString HEADER_REQUEST_METHOD_HEAD = u"HEAD"_qs;
64 inline const QString HEADER_REQUEST_METHOD_POST = u"POST"_qs;
66 inline const QString CONTENT_TYPE_HTML = u"text/html"_qs;
67 inline const QString CONTENT_TYPE_CSS = u"text/css"_qs;
68 inline const QString CONTENT_TYPE_TXT = u"text/plain; charset=UTF-8"_qs;
69 inline const QString CONTENT_TYPE_JS = u"application/javascript"_qs;
70 inline const QString CONTENT_TYPE_JSON = u"application/json"_qs;
71 inline const QString CONTENT_TYPE_GIF = u"image/gif"_qs;
72 inline const QString CONTENT_TYPE_PNG = u"image/png"_qs;
73 inline const QString CONTENT_TYPE_FORM_ENCODED = u"application/x-www-form-urlencoded"_qs;
74 inline const QString CONTENT_TYPE_FORM_DATA = u"multipart/form-data"_qs;
76 // portability: "\r\n" doesn't guarantee mapping to the correct symbol
77 inline const char CRLF[] = {0x0D, 0x0A, '\0'};
79 struct Environment
81 QHostAddress localAddress;
82 quint16 localPort;
84 QHostAddress clientAddress;
85 quint16 clientPort;
88 struct UploadedFile
90 QString filename;
91 QString type; // MIME type
92 QByteArray data;
95 struct Header
97 QString name;
98 QString value;
101 using HeaderMap = QMap<QString, QString>; // <Header name, Header value>
103 struct Request
105 QString version;
106 QString method;
107 QString path;
108 HeaderMap headers;
109 QHash<QString, QByteArray> query;
110 QHash<QString, QString> posts;
111 QVector<UploadedFile> files;
114 struct ResponseStatus
116 uint code;
117 QString text;
120 struct Response
122 ResponseStatus status;
123 HeaderMap headers;
124 QByteArray content;
126 Response(uint code = 200, const QString &text = u"OK"_qs)
127 : status {code, text}