Implemented file handling from resource system
This commit is contained in:
@ -10,6 +10,8 @@ HEADERS += streamingwebserver.h
|
||||
SOURCES += main.cpp \
|
||||
streamingwebserver.cpp
|
||||
|
||||
RESOURCES += resources.qrc
|
||||
|
||||
OTHER_FILES += .dockerignore \
|
||||
Dockerfile
|
||||
|
||||
|
3
htdocs/css/style.css
Normal file
3
htdocs/css/style.css
Normal file
@ -0,0 +1,3 @@
|
||||
/**
|
||||
* Stylesheet
|
||||
*/
|
21
htdocs/index.html
Normal file
21
htdocs/index.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||
<title>1000serien.com</title>
|
||||
<meta name="description" content="This page is still under construction" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
||||
|
||||
<link rel="stylesheet" href="css/style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>1000serien.com</h1>
|
||||
<p>This page is still under construction</p>
|
||||
|
||||
<script src="js/script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
3
htdocs/js/script.js
Normal file
3
htdocs/js/script.js
Normal file
@ -0,0 +1,3 @@
|
||||
/**
|
||||
* Script
|
||||
*/
|
7
resources.qrc
Normal file
7
resources.qrc
Normal file
@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/StreamingWebserver">
|
||||
<file>htdocs/index.html</file>
|
||||
<file>htdocs/css/style.css</file>
|
||||
<file>htdocs/js/script.js</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -1,5 +1,9 @@
|
||||
#include "streamingwebserver.h"
|
||||
|
||||
#include <QStringBuilder>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
||||
#include "httpclientconnection.h"
|
||||
#include "httpcontainers.h"
|
||||
|
||||
@ -12,9 +16,24 @@ void StreamingWebserver::handleRequest(HttpClientConnection *connection, const H
|
||||
{
|
||||
HttpResponse response;
|
||||
response.protocol = request.protocol;
|
||||
response.statusCode = HttpResponse::StatusCode::NotFound;
|
||||
response.headers.insert(QStringLiteral("Server"), QStringLiteral("Hatschi Server 1.0"));
|
||||
response.headers.insert(QStringLiteral("Content-Type"), QStringLiteral("text/html"));
|
||||
|
||||
connection->sendResponse(response, tr("Not Found"));
|
||||
auto path = QStringLiteral(":/StreamingWebserver/htdocs") %
|
||||
QDir::separator() %
|
||||
(request.path == QStringLiteral("/") ? QStringLiteral("index.html") : request.path);
|
||||
|
||||
qDebug() << request.path << path;
|
||||
|
||||
std::unique_ptr<QIODevice> device = std::make_unique<QFile>(path);
|
||||
if(device->open(QIODevice::ReadOnly))
|
||||
{
|
||||
response.statusCode = HttpResponse::StatusCode::OK;
|
||||
connection->sendResponse(response, std::move(device));
|
||||
}
|
||||
else
|
||||
{
|
||||
response.statusCode = HttpResponse::StatusCode::NotFound;
|
||||
connection->sendResponse(response, tr("Not Found"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user