MythTV master
mythhttprewrite.cpp
Go to the documentation of this file.
1// MythTV
2#include "mythdirs.h"
3#include "mythlogging.h"
5#include "http/mythhttpdata.h"
6#include "http/mythhttpfile.h"
9
10
23{
24 auto result = static_cast<HTTPResponse>(nullptr);
25 if (!Request)
26 return result;
27
28 LOG(VB_HTTP, LOG_INFO, QString("Rewriting request to new file '%1'").arg(File));
29 if (!File.isEmpty())
30 {
31 Request->m_fileName = File;
33 }
34 return result;
35
36}
37
55{
56 auto result = static_cast<HTTPResponse>(nullptr);
57 if (!Request)
58 return result;
59
60 if (Request->m_path == "/" &&
61 (Request->m_fileName.endsWith(".js") || Request->m_fileName.endsWith(".css")))
62 {
63 LOG(VB_HTTP, LOG_INFO, QString("Rewriting request %1 to web app '%2'")
64 .arg(Request->m_path + Request->m_fileName, File));
65 int ix = File.lastIndexOf('/');
66 Request->m_path = "/" + File.left(ix+1);
67 Request->m_status = HTTPOK;
69 }
70 else if (!File.isEmpty()
71 && (Request->m_path.isEmpty() || Request->m_path == "/"
72 || Request->m_path == "/dashboard/" || Request->m_path == "/setupwizard/"
73 || Request->m_path == "/MythFE/"))
74 {
75 LOG(VB_HTTP, LOG_INFO, QString("Rewriting request to web app '%1'").arg(File));
76 Request->m_fileName = File;
77 Request->m_status = HTTPOK;
78 Request->m_path = "/";
80 }
81
82 return result;
83}
static HTTPResponse ProcessFile(const HTTPRequest2 &Request)
static HTTPResponse RewriteFile(const HTTPRequest2 &Request, const QString &File)
A convenience method to seemlessly redirect requests for files to a context specific file.
static HTTPResponse RewriteToSPA(const HTTPRequest2 &Request, const QString &File)
A convenience method to seemlessly redirect requests to a Single Page web app (SPA)
std::shared_ptr< MythHTTPRequest > HTTPRequest2
Definition: mythhttptypes.h:39
std::shared_ptr< MythHTTPResponse > HTTPResponse
Definition: mythhttptypes.h:40
@ HTTPOK
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39