mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 11:56:17 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into metavoxels
This commit is contained in:
commit
2f23d918f6
3 changed files with 21 additions and 7 deletions
|
@ -15,8 +15,10 @@
|
||||||
#include "HTTPManager.h"
|
#include "HTTPManager.h"
|
||||||
|
|
||||||
const char* HTTPConnection::StatusCode200 = "200 OK";
|
const char* HTTPConnection::StatusCode200 = "200 OK";
|
||||||
|
const char* HTTPConnection::StatusCode301 = "301 Moved Permanently";
|
||||||
const char* HTTPConnection::StatusCode400 = "400 Bad Request";
|
const char* HTTPConnection::StatusCode400 = "400 Bad Request";
|
||||||
const char* HTTPConnection::StatusCode404 = "404 Not Found";
|
const char* HTTPConnection::StatusCode404 = "404 Not Found";
|
||||||
|
const char* HTTPConnection::DefaultContentType = "text/plain; charset=ISO-8859-1";
|
||||||
|
|
||||||
HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager) :
|
HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager) :
|
||||||
QObject(parentManager),
|
QObject(parentManager),
|
||||||
|
|
|
@ -40,8 +40,10 @@ class HTTPConnection : public QObject {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const char* StatusCode200;
|
static const char* StatusCode200;
|
||||||
|
static const char* StatusCode301;
|
||||||
static const char* StatusCode400;
|
static const char* StatusCode400;
|
||||||
static const char* StatusCode404;
|
static const char* StatusCode404;
|
||||||
|
static const char* DefaultContentType;
|
||||||
|
|
||||||
/// WebSocket close status codes.
|
/// WebSocket close status codes.
|
||||||
enum ReasonCode { NoReason = 0, NormalClosure = 1000, GoingAway = 1001 };
|
enum ReasonCode { NoReason = 0, NormalClosure = 1000, GoingAway = 1001 };
|
||||||
|
@ -72,7 +74,7 @@ public:
|
||||||
|
|
||||||
/// Sends a response and closes the connection.
|
/// Sends a response and closes the connection.
|
||||||
void respond (const char* code, const QByteArray& content = QByteArray(),
|
void respond (const char* code, const QByteArray& content = QByteArray(),
|
||||||
const char* contentType = "text/plain; charset=ISO-8859-1",
|
const char* contentType = DefaultContentType,
|
||||||
const Headers& headers = Headers());
|
const Headers& headers = Headers());
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|
|
@ -23,7 +23,6 @@ bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QString& p
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if there is a file to serve from the document root for this path
|
// check to see if there is a file to serve from the document root for this path
|
||||||
|
|
||||||
QString subPath = path;
|
QString subPath = path;
|
||||||
|
|
||||||
// remove any slash at the beginning of the path
|
// remove any slash at the beginning of the path
|
||||||
|
@ -33,6 +32,19 @@ bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QString& p
|
||||||
|
|
||||||
QString filePath;
|
QString filePath;
|
||||||
|
|
||||||
|
if (QFileInfo(_documentRoot + subPath).isFile()) {
|
||||||
|
filePath = _documentRoot + subPath;
|
||||||
|
} else if (subPath.size() > 0 && !subPath.endsWith('/')) {
|
||||||
|
// this could be a directory with a trailing slash
|
||||||
|
// send a redirect to the path with a slash so we can
|
||||||
|
QString redirectLocation = '/' + subPath + '/';
|
||||||
|
|
||||||
|
QHash<QByteArray, QByteArray> redirectHeader;
|
||||||
|
redirectHeader.insert(QByteArray("Location"), redirectLocation.toUtf8());
|
||||||
|
|
||||||
|
connection->respond(HTTPConnection::StatusCode301, "", HTTPConnection::DefaultContentType, redirectHeader);
|
||||||
|
}
|
||||||
|
|
||||||
// if the last thing is a trailing slash then we want to look for index file
|
// if the last thing is a trailing slash then we want to look for index file
|
||||||
if (subPath.endsWith('/') || subPath.size() == 0) {
|
if (subPath.endsWith('/') || subPath.size() == 0) {
|
||||||
QStringList possibleIndexFiles = QStringList() << "index.html" << "index.shtml";
|
QStringList possibleIndexFiles = QStringList() << "index.html" << "index.shtml";
|
||||||
|
@ -43,14 +55,10 @@ bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QString& p
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (QFileInfo(_documentRoot + subPath).isFile()) {
|
|
||||||
filePath = _documentRoot + subPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!filePath.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
// file exists, serve it
|
// file exists, serve it
|
||||||
|
|
||||||
static QMimeDatabase mimeDatabase;
|
static QMimeDatabase mimeDatabase;
|
||||||
|
|
||||||
QFile localFile(filePath);
|
QFile localFile(filePath);
|
||||||
|
@ -99,8 +107,10 @@ bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QString& p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection->respond(HTTPConnection::StatusCode200, localFileString.toLocal8Bit(), qPrintable(mimeDatabase.mimeTypeForFile(filePath).name()));
|
connection->respond(HTTPConnection::StatusCode200, localFileString.toLocal8Bit(),
|
||||||
|
qPrintable(mimeDatabase.mimeTypeForFile(filePath).name()));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// respond with a 404
|
// respond with a 404
|
||||||
connection->respond(HTTPConnection::StatusCode404, "Resource not found.");
|
connection->respond(HTTPConnection::StatusCode404, "Resource not found.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue