MythTV  master
mythhttpresponse.h
Go to the documentation of this file.
1 #ifndef MYTHHTTPRESPONSE_H
2 #define MYTHHTTPRESPONSE_H
3 
4 // Std
5 #include <vector>
6 
7 // MythTV
13 
14 class QTcpSocket;
15 
17 {
18  public:
19  MythHTTPResponse() = default;
20  explicit MythHTTPResponse(const HTTPRequest2& Request);
21 
22  static HTTPResponse HandleOptions (const HTTPRequest2& Request);
23  static HTTPResponse ErrorResponse (MythHTTPStatus Status, const QString& ServerName);
24  static HTTPResponse RedirectionResponse (const HTTPRequest2& Request, const QString& Redirect);
25  static HTTPResponse ErrorResponse (const HTTPRequest2& Request, const QString& Message = {});
26  static HTTPResponse OptionsResponse (const HTTPRequest2& Request);
27  static HTTPResponse DataResponse (const HTTPRequest2& Request, const HTTPData& Data);
28  static HTTPResponse FileResponse (const HTTPRequest2& Request, const HTTPFile& File);
29  static HTTPResponse EmptyResponse (const HTTPRequest2& Request);
30  static HTTPResponse UpgradeResponse (const HTTPRequest2& Request, MythSocketProtocol& Protocol, bool& Testing);
31 
32  void Finalise (const MythHTTPConfig& Config);
33  template <class T>
34  std::enable_if_t<std::is_convertible_v<T, QString>, void>
35  AddHeader (const QString& key, const T& val)
36  {
37  QByteArray bytes = QString("%1: %2\r\n").arg(key, val).toUtf8();
38  m_responseHeaders.emplace_back(MythHTTPData::Create(bytes));
39  }
40  template <class T>
41  std::enable_if_t<!std::is_convertible_v<T, QString>, void>
42  AddHeader (const QString& key, T val)
43  {
44  QByteArray bytes = QString("%1: %2\r\n").arg(key).arg(val).toUtf8();
45  m_responseHeaders.emplace_back(MythHTTPData::Create(bytes));
46  }
47 
48  QString m_serverName;
51  std::chrono::milliseconds m_timeout { HTTP_SOCKET_TIMEOUT_MS };
53  MythHTTPRequestType m_requestType { HTTPGet };
54  int m_allowed { HTTP_DEFAULT_ALLOWED };
55  HTTPHeaders m_requestHeaders { nullptr };
57  HTTPVariant m_response { std::monostate() };
58 
59  protected:
60  void AddDefaultHeaders();
61  void AddContentHeaders();
62 
63  private:
64  Q_DISABLE_COPY(MythHTTPResponse)
65 };
66 
67 #endif
MythSocketProtocol
MythSocketProtocol
Definition: mythhttpcommon.h:25
MythHTTPResponse::m_serverName
QString m_serverName
Definition: mythhttpresponse.h:48
HTTPGet
@ HTTPGet
Definition: mythhttptypes.h:93
HTTPVariant
std::variant< std::monostate, HTTPData, HTTPFile > HTTPVariant
Definition: mythhttptypes.h:41
MythHTTPResponse
Definition: mythhttpresponse.h:16
HTTP_DEFAULT_ALLOWED
#define HTTP_DEFAULT_ALLOWED
Definition: mythhttptypes.h:102
mythhttpdata.h
HTTPData
std::shared_ptr< MythHTTPData > HTTPData
Definition: mythhttptypes.h:36
HTTPHeaders
std::shared_ptr< HTTPMap > HTTPHeaders
Definition: mythhttptypes.h:35
mythhttpfile.h
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythHTTPVersion
MythHTTPVersion
Definition: mythhttptypes.h:81
HTTPContents
std::vector< HTTPData > HTTPContents
Definition: mythhttptypes.h:37
MythHTTPStatus
MythHTTPStatus
Definition: mythhttptypes.h:104
MythHTTPData::Create
static HTTPData Create()
Definition: mythhttpdata.cpp:4
MythHTTPRequestType
MythHTTPRequestType
Definition: mythhttptypes.h:89
HTTPConnectionClose
@ HTTPConnectionClose
Definition: mythhttptypes.h:129
MythHTTPResponse::AddHeader
std::enable_if_t<!std::is_convertible_v< T, QString >, void > AddHeader(const QString &key, T val)
Definition: mythhttpresponse.h:42
mythhttptypes.h
HTTPOneDotOne
@ HTTPOneDotOne
Definition: mythhttptypes.h:86
HTTPResponse
std::shared_ptr< MythHTTPResponse > HTTPResponse
Definition: mythhttptypes.h:39
hardwareprofile.distros.mythtv_data.request.Request
def Request(url=None)
Definition: request.py:62
HTTP_SOCKET_TIMEOUT_MS
#define HTTP_SOCKET_TIMEOUT_MS
Definition: mythhttptypes.h:24
musicbrainzngs.compat.bytes
bytes
Definition: compat.py:49
HTTPBadRequest
@ HTTPBadRequest
Definition: mythhttptypes.h:112
HTTPRequest2
std::shared_ptr< MythHTTPRequest > HTTPRequest2
Definition: mythhttptypes.h:38
mythhttprequest.h
MythHTTPResponse::AddHeader
std::enable_if_t< std::is_convertible_v< T, QString >, void > AddHeader(const QString &key, const T &val)
Definition: mythhttpresponse.h:35
MythHTTPConfig
Definition: mythhttptypes.h:60
HTTPFile
std::shared_ptr< MythHTTPFile > HTTPFile
Definition: mythhttptypes.h:40
mythwebsockettypes.h
MythHTTPResponse::m_responseHeaders
HTTPContents m_responseHeaders
Definition: mythhttpresponse.h:56
MythHTTPConnection
MythHTTPConnection
Definition: mythhttptypes.h:127