sic/src/StaticFileHandler.cc

59 lines
1.2 KiB
C++

#include "StaticFileHandler.H"
//#include "InputMemmoryFile.H"
static const char * hello_world_html = u8R"HERE(
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title></title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<h1 id="sharing-is-caring">Sharing is caring</h1>
<p>Hello World!</p>
<h2 id="it-works">It works</h2>
<p>It seems like a working page has been served</p>
</body>
</html>)HERE";
class UltraSimpleStaticFileHandler : StaticFileHandler
{
public:
int answer_pathreq(const char * const path, struct mg_connection *conn)
{
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
"Content-Length: %d\r\n"
"Content-Type: text/html\r\n\r\n%s",
hello_world_html.size(),
hello_world_html.c_str());
return 0;
}
};
class MediocreSimpleStaticFileHandler :StaticFileHandler
{
private:
std::string cleanpath (const char * const path){
//adds no security at all
return std::string(path);
}
public:
int answer_pathreq(const char * const path,
struct mg_connection *conn)
{
mg_send_file(conn,cleanpath(path).to_cstring());
return 0;
}
}