1 #ifndef MYTHHTTPTYPES_H
2 #define MYTHHTTPTYPES_H
14 #include <QStringList>
15 #include <QHostAddress>
17 #include <QSslConfiguration>
25 #define HTTP_SOCKET_TIMEOUT_MS 10000 // 10 seconds
26 #define HTTP_SERVICES_DIR QString("/services/")
34 using HTTPMap = QMultiMap<QString,QString>;
37 using HTTPData = std::shared_ptr<MythHTTPData>;
41 using HTTPFile = std::shared_ptr<MythHTTPFile>;
42 using HTTPVariant = std::variant<std::monostate, HTTPData, HTTPFile>;
65 quint16 m_port_2 { 0 };
66 quint16 m_sslPort { 0 };
103 #define HTTP_DEFAULT_ALLOWED (HTTPHead | HTTPGet | HTTPOptions | HTTPPost)
159 "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=ISO-8859-1\">"
161 "<BODY><H1>%1</H1></BODY>"
193 return QStringLiteral(
"Error");
198 if (Version.startsWith(QStringLiteral(
"HTTP")))
200 if (Version.endsWith(QStringLiteral(
"1.1")))
return HTTPOneDotOne;
201 if (Version.endsWith(QStringLiteral(
"1.0")))
return HTTPOneDotZero;
211 case HTTPHead:
return QStringLiteral(
"HEAD");
212 case HTTPGet:
return QStringLiteral(
"GET");
213 case HTTPPost:
return QStringLiteral(
"POST");
214 case HTTPPut:
return QStringLiteral(
"PUT");
215 case HTTPDelete:
return QStringLiteral(
"DELETE");
216 case HTTPOptions:
return QStringLiteral(
"OPTIONS");
219 return QStringLiteral(
"Error");
224 if (Type == QStringLiteral(
"GET"))
return HTTPGet;
225 if (Type == QStringLiteral(
"HEAD"))
return HTTPHead;
226 if (Type == QStringLiteral(
"POST"))
return HTTPPost;
227 if (Type == QStringLiteral(
"PUT"))
return HTTPPut;
228 if (Type == QStringLiteral(
"OPTIONS"))
return HTTPOptions;
229 if (Type == QStringLiteral(
"DELETE"))
return HTTPDelete;
236 if (Allowed &
HTTPHead) result << QStringLiteral(
"HEAD");
237 if (Allowed &
HTTPGet) result << QStringLiteral(
"GET");
238 if (Allowed &
HTTPPost) result << QStringLiteral(
"POST");
239 if (Allowed &
HTTPPut) result << QStringLiteral(
"PUT");
240 if (Allowed &
HTTPDelete) result << QStringLiteral(
"DELETE");
241 if (Allowed &
HTTPOptions) result << QStringLiteral(
"OPTIONS");
242 return result.join(QStringLiteral(
", "));
248 if (Requests.contains(
"HEAD", Qt::CaseInsensitive)) result |=
HTTPHead;
249 if (Requests.contains(
"GET", Qt::CaseInsensitive)) result |=
HTTPGet;
250 if (Requests.contains(
"POST", Qt::CaseInsensitive)) result |=
HTTPPost;
251 if (Requests.contains(
"PUT", Qt::CaseInsensitive)) result |=
HTTPPut;
252 if (Requests.contains(
"DELETE", Qt::CaseInsensitive)) result |=
HTTPDelete;
253 if (Requests.contains(
"OPTIONS", Qt::CaseInsensitive)) result |=
HTTPOptions;
262 case HTTPOK:
return QStringLiteral(
"200 OK");
263 case HTTPAccepted:
return QStringLiteral(
"202 Accepted");
270 case HTTPNotFound:
return QStringLiteral(
"404 Not Found");
281 return QStringLiteral(
"Error");
286 if (Status.startsWith(QStringLiteral(
"200")))
return HTTPOK;
293 if (Status.startsWith(QStringLiteral(
"403")))
return HTTPForbidden;
294 if (Status.startsWith(QStringLiteral(
"404")))
return HTTPNotFound;
300 if (Status.startsWith(QStringLiteral(
"501")))
return HTTPBadGateway;
314 return QStringLiteral(
"keep-alive");
320 if (Headers && Headers->contains(Value))
321 return Headers->value(Value);
329 type +=
"; charset=\"UTF-8\"";
335 if (Address.protocol() == QAbstractSocket::IPv6Protocol)
337 Address.setScopeId(
"");
338 return QString(
"[%1]").arg(Address.toString());
340 return Address.toString();