mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-22 20:44:56 +00:00
serve html files from ~/.twister/html (actually dataDir + "/html")
This commit is contained in:
parent
bd479f0b2e
commit
6957873a90
@ -981,14 +981,16 @@ void ServiceConnection(AcceptedConnection *conn)
|
|||||||
// Read HTTP message headers and body
|
// Read HTTP message headers and body
|
||||||
ReadHTTPMessage(conn->stream(), mapHeaders, strRequest, nProto);
|
ReadHTTPMessage(conn->stream(), mapHeaders, strRequest, nProto);
|
||||||
|
|
||||||
if (strURI != "/") {
|
if (strURI != "/" && strURI.find("..") == std::string::npos ) {
|
||||||
std::vector<char> file_data;
|
filesystem::path pathFile = filesystem::path(GetDataDir()) / "html" / strURI;
|
||||||
std::string fname = strURI;
|
std::string fname = pathFile.string();
|
||||||
size_t qMarkIdx = fname.find('?');
|
size_t qMarkIdx = fname.find('?');
|
||||||
if( qMarkIdx != string::npos ) {
|
if( qMarkIdx != string::npos ) {
|
||||||
fname.resize(qMarkIdx);
|
fname.resize(qMarkIdx);
|
||||||
}
|
}
|
||||||
if( load_file(fname.c_str(), file_data) == 0 ) {
|
|
||||||
|
std::vector<char> file_data;
|
||||||
|
if( load_file( fname.c_str(), file_data) == 0 ) {
|
||||||
std::string str(file_data.data(), file_data.size());
|
std::string str(file_data.data(), file_data.size());
|
||||||
const char *contentType = "text/html";
|
const char *contentType = "text/html";
|
||||||
if( strURI.find(".js") != std::string::npos )
|
if( strURI.find(".js") != std::string::npos )
|
||||||
@ -1004,6 +1006,7 @@ void ServiceConnection(AcceptedConnection *conn)
|
|||||||
contentType = "image/jpeg";
|
contentType = "image/jpeg";
|
||||||
conn->stream() << HTTPReply(HTTP_OK, str, false, contentType) << std::flush;
|
conn->stream() << HTTPReply(HTTP_OK, str, false, contentType) << std::flush;
|
||||||
} else {
|
} else {
|
||||||
|
printf("ServiceConnection: file %s not found\n", fname.c_str());
|
||||||
conn->stream() << HTTPReply(HTTP_NOT_FOUND, "", false) << std::flush;
|
conn->stream() << HTTPReply(HTTP_NOT_FOUND, "", false) << std::flush;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user