uppercase the names of the HTTP classes

This commit is contained in:
Stephen Birarda 2014-01-17 11:53:47 -08:00
parent 5625000485
commit ce393fdf27
6 changed files with 53 additions and 53 deletions

View file

@ -13,7 +13,7 @@
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <HttpConnection.h> #include <HTTPConnection.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <UUID.h> #include <UUID.h>
@ -34,7 +34,7 @@ const quint16 DOMAIN_SERVER_HTTP_PORT = 8080;
DomainServer::DomainServer(int argc, char* argv[]) : DomainServer::DomainServer(int argc, char* argv[]) :
QCoreApplication(argc, argv), QCoreApplication(argc, argv),
_httpManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this), _HTTPManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this),
_assignmentQueueMutex(), _assignmentQueueMutex(),
_assignmentQueue(), _assignmentQueue(),
_staticAssignmentFile(QString("%1/config.ds").arg(QCoreApplication::applicationDirPath())), _staticAssignmentFile(QString("%1/config.ds").arg(QCoreApplication::applicationDirPath())),
@ -294,7 +294,7 @@ QJsonObject jsonObjectForNode(Node* node) {
return nodeJson; return nodeJson;
} }
bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString& path) { bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString& path) {
const QString JSON_MIME_TYPE = "application/json"; const QString JSON_MIME_TYPE = "application/json";
const QString URI_ASSIGNMENT = "/assignment"; const QString URI_ASSIGNMENT = "/assignment";
@ -346,7 +346,7 @@ bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString&
// print out the created JSON // print out the created JSON
QJsonDocument assignmentDocument(assignmentJSON); QJsonDocument assignmentDocument(assignmentJSON);
connection->respond(HttpConnection::StatusCode200, assignmentDocument.toJson(), qPrintable(JSON_MIME_TYPE)); connection->respond(HTTPConnection::StatusCode200, assignmentDocument.toJson(), qPrintable(JSON_MIME_TYPE));
// we've processed this request // we've processed this request
return true; return true;
@ -370,11 +370,11 @@ bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString&
QJsonDocument nodesDocument(rootJSON); QJsonDocument nodesDocument(rootJSON);
// send the response // send the response
connection->respond(HttpConnection::StatusCode200, nodesDocument.toJson(), qPrintable(JSON_MIME_TYPE)); connection->respond(HTTPConnection::StatusCode200, nodesDocument.toJson(), qPrintable(JSON_MIME_TYPE));
} }
} else if (connection->requestOperation() == QNetworkAccessManager::PostOperation) { } else if (connection->requestOperation() == QNetworkAccessManager::PostOperation) {
if (path == URI_ASSIGNMENT) { if (path == URI_ASSIGNMENT) {
// this is a script upload - ask the HttpConnection to parse the form data // this is a script upload - ask the HTTPConnection to parse the form data
QList<FormData> formData = connection->parseFormData(); QList<FormData> formData = connection->parseFormData();
qDebug() << formData; qDebug() << formData;
} }
@ -390,7 +390,7 @@ bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString&
if (nodeToKill) { if (nodeToKill) {
// start with a 200 response // start with a 200 response
connection->respond(HttpConnection::StatusCode200); connection->respond(HTTPConnection::StatusCode200);
// we have a valid UUID and node - kill the node that has this assignment // we have a valid UUID and node - kill the node that has this assignment
QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID)); QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
@ -401,7 +401,7 @@ bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString&
} }
// bad request, couldn't pull a node ID // bad request, couldn't pull a node ID
connection->respond(HttpConnection::StatusCode400); connection->respond(HTTPConnection::StatusCode400);
return true; return true;
} }

View file

@ -16,7 +16,7 @@
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <Assignment.h> #include <Assignment.h>
#include <HttpManager.h> #include <HTTPManager.h>
#include <NodeList.h> #include <NodeList.h>
const int MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS = 1000; const int MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS = 1000;
@ -26,7 +26,7 @@ class DomainServer : public QCoreApplication, public HttpRequestHandler {
public: public:
DomainServer(int argc, char* argv[]); DomainServer(int argc, char* argv[]);
bool handleHTTPRequest(HttpConnection* connection, const QString& path); bool handleHTTPRequest(HTTPConnection* connection, const QString& path);
void exit(int retCode = 0); void exit(int retCode = 0);
@ -50,7 +50,7 @@ private:
unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd); unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd);
HttpManager _httpManager; HTTPManager _HTTPManager;
QMutex _assignmentQueueMutex; QMutex _assignmentQueueMutex;
std::deque<Assignment*> _assignmentQueue; std::deque<Assignment*> _assignmentQueue;

View file

@ -1,5 +1,5 @@
// //
// HttpConnection.cpp // HTTPConnection.cpp
// hifi // hifi
// //
// Created by Stephen Birarda on 1/16/14. // Created by Stephen Birarda on 1/16/14.
@ -11,14 +11,14 @@
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QTcpSocket> #include <QTcpSocket>
#include "HttpConnection.h" #include "HTTPConnection.h"
#include "HttpManager.h" #include "HTTPManager.h"
const char* HttpConnection::StatusCode200 = "200 OK"; const char* HTTPConnection::StatusCode200 = "200 OK";
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";
HttpConnection::HttpConnection (QTcpSocket* socket, HttpManager* parentManager) : HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager) :
QObject(parentManager), QObject(parentManager),
_parentManager(parentManager), _parentManager(parentManager),
_socket(socket), _socket(socket),
@ -34,14 +34,14 @@ HttpConnection::HttpConnection (QTcpSocket* socket, HttpManager* parentManager)
connect(socket, SIGNAL(disconnected()), SLOT(deleteLater())); connect(socket, SIGNAL(disconnected()), SLOT(deleteLater()));
} }
HttpConnection::~HttpConnection() { HTTPConnection::~HTTPConnection() {
// log the destruction // log the destruction
if (_socket->error() != QAbstractSocket::UnknownSocketError) { if (_socket->error() != QAbstractSocket::UnknownSocketError) {
qDebug() << _socket->errorString(); qDebug() << _socket->errorString();
} }
} }
QList<FormData> HttpConnection::parseFormData() const { QList<FormData> HTTPConnection::parseFormData() const {
// make sure we have the correct MIME type // make sure we have the correct MIME type
QList<QByteArray> elements = _requestHeaders.value("Content-Type").split(';'); QList<QByteArray> elements = _requestHeaders.value("Content-Type").split(';');
if (elements.at(0).trimmed() != "multipart/form-data") { if (elements.at(0).trimmed() != "multipart/form-data") {
@ -97,7 +97,7 @@ QList<FormData> HttpConnection::parseFormData() const {
return data; return data;
} }
void HttpConnection::respond(const char* code, const QByteArray& content, const char* contentType, const Headers& headers) { void HTTPConnection::respond(const char* code, const QByteArray& content, const char* contentType, const Headers& headers) {
_socket->write("HTTP/1.1 "); _socket->write("HTTP/1.1 ");
_socket->write(code); _socket->write(code);
_socket->write("\r\n"); _socket->write("\r\n");
@ -132,7 +132,7 @@ void HttpConnection::respond(const char* code, const QByteArray& content, const
_socket->disconnectFromHost(); _socket->disconnectFromHost();
} }
void HttpConnection::readRequest() { void HTTPConnection::readRequest() {
if (!_socket->canReadLine()) { if (!_socket->canReadLine()) {
return; return;
} }
@ -169,7 +169,7 @@ void HttpConnection::readRequest() {
readHeaders(); readHeaders();
} }
void HttpConnection::readHeaders() { void HTTPConnection::readHeaders() {
while (_socket->canReadLine()) { while (_socket->canReadLine()) {
QByteArray line = _socket->readLine(); QByteArray line = _socket->readLine();
QByteArray trimmed = line.trimmed(); QByteArray trimmed = line.trimmed();
@ -209,7 +209,7 @@ void HttpConnection::readHeaders() {
} }
} }
void HttpConnection::readContent() { void HTTPConnection::readContent() {
int size = _requestContent.size(); int size = _requestContent.size();
if (_socket->bytesAvailable() < size) { if (_socket->bytesAvailable() < size) {
return; return;

View file

@ -1,17 +1,17 @@
// //
// HttpConnection.h // HTTPConnection.h
// hifi // hifi
// //
// Created by Stephen Birarda on 1/16/14. // Created by Stephen Birarda on 1/16/14.
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved. // Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
// //
// Heavily based on Andrzej Kapolka's original HttpConnection class // Heavily based on Andrzej Kapolka's original HTTPConnection class
// found from another one of his projects. // found from another one of his projects.
// https://github.com/ey6es/witgap/tree/master/src/cpp/server/http // https://github.com/ey6es/witgap/tree/master/src/cpp/server/http
// //
#ifndef __hifi__HttpConnection__ #ifndef __hifi__HTTPConnection__
#define __hifi__HttpConnection__ #define __hifi__HTTPConnection__
#include <QHash> #include <QHash>
#include <QHostAddress> #include <QHostAddress>
@ -23,7 +23,7 @@
#include <QUrl> #include <QUrl>
class QTcpSocket; class QTcpSocket;
class HttpManager; class HTTPManager;
class MaskFilter; class MaskFilter;
class ServerApp; class ServerApp;
@ -34,7 +34,7 @@ typedef QHash<QByteArray, QByteArray> Headers;
typedef QPair<Headers, QByteArray> FormData; typedef QPair<Headers, QByteArray> FormData;
/// Handles a single HTTP connection. /// Handles a single HTTP connection.
class HttpConnection : public QObject { class HTTPConnection : public QObject {
Q_OBJECT Q_OBJECT
public: public:
@ -46,10 +46,10 @@ public:
enum ReasonCode { NoReason = 0, NormalClosure = 1000, GoingAway = 1001 }; enum ReasonCode { NoReason = 0, NormalClosure = 1000, GoingAway = 1001 };
/// Initializes the connection. /// Initializes the connection.
HttpConnection (QTcpSocket* socket, HttpManager* parentManager); HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager);
/// Destroys the connection. /// Destroys the connection.
virtual ~HttpConnection (); virtual ~HTTPConnection ();
/// Returns a pointer to the underlying socket, to which WebSocket message bodies should be written. /// Returns a pointer to the underlying socket, to which WebSocket message bodies should be written.
QTcpSocket* socket () const { return _socket; } QTcpSocket* socket () const { return _socket; }
@ -88,7 +88,7 @@ protected slots:
protected: protected:
/// The parent HTTP manager /// The parent HTTP manager
HttpManager* _parentManager; HTTPManager* _parentManager;
/// The underlying socket. /// The underlying socket.
QTcpSocket* _socket; QTcpSocket* _socket;
@ -115,4 +115,4 @@ protected:
QByteArray _requestContent; QByteArray _requestContent;
}; };
#endif /* defined(__hifi__HttpConnection__) */ #endif /* defined(__hifi__HTTPConnection__) */

View file

@ -1,5 +1,5 @@
// //
// HttpManager.cpp // HTTPManager.cpp
// hifi // hifi
// //
// Created by Stephen Birarda on 1/16/14. // Created by Stephen Birarda on 1/16/14.
@ -12,10 +12,10 @@
#include <QtCore/QMimeDatabase> #include <QtCore/QMimeDatabase>
#include <QtNetwork/QTcpSocket> #include <QtNetwork/QTcpSocket>
#include "HttpConnection.h" #include "HTTPConnection.h"
#include "HttpManager.h" #include "HTTPManager.h"
bool HttpManager::handleHTTPRequest(HttpConnection* connection, const QString& path) { bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QString& path) {
if (_requestHandler && _requestHandler->handleHTTPRequest(connection, path)) { if (_requestHandler && _requestHandler->handleHTTPRequest(connection, path)) {
// this request was handled by our _requestHandler object // this request was handled by our _requestHandler object
// so we don't need to attempt to do so in the document root // so we don't need to attempt to do so in the document root
@ -99,16 +99,16 @@ 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.");
} }
return true; return true;
} }
HttpManager::HttpManager(quint16 port, const QString& documentRoot, HttpRequestHandler* requestHandler, QObject* parent) : HTTPManager::HTTPManager(quint16 port, const QString& documentRoot, HttpRequestHandler* requestHandler, QObject* parent) :
QTcpServer(parent), QTcpServer(parent),
_documentRoot(documentRoot), _documentRoot(documentRoot),
_requestHandler(requestHandler) _requestHandler(requestHandler)
@ -123,9 +123,9 @@ HttpManager::HttpManager(quint16 port, const QString& documentRoot, HttpRequestH
connect(this, SIGNAL(newConnection()), SLOT(acceptConnections())); connect(this, SIGNAL(newConnection()), SLOT(acceptConnections()));
} }
void HttpManager::acceptConnections() { void HTTPManager::acceptConnections() {
QTcpSocket* socket; QTcpSocket* socket;
while ((socket = nextPendingConnection()) != 0) { while ((socket = nextPendingConnection()) != 0) {
new HttpConnection(socket, this); new HTTPConnection(socket, this);
} }
} }

View file

@ -1,36 +1,36 @@
// //
// HttpManager.h // HTTPManager.h
// hifi // hifi
// //
// Created by Stephen Birarda on 1/16/14. // Created by Stephen Birarda on 1/16/14.
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved. // Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
// //
// Heavily based on Andrzej Kapolka's original HttpManager class // Heavily based on Andrzej Kapolka's original HTTPManager class
// found from another one of his projects. // found from another one of his projects.
// https://github.com/ey6es/witgap/tree/master/src/cpp/server/http // https://github.com/ey6es/witgap/tree/master/src/cpp/server/http
// //
#ifndef __hifi__HttpManager__ #ifndef __hifi__HTTPManager__
#define __hifi__HttpManager__ #define __hifi__HTTPManager__
#include <QtNetwork/QTcpServer> #include <QtNetwork/QTcpServer>
class HttpConnection; class HTTPConnection;
class HttpRequestHandler { class HttpRequestHandler {
public: public:
/// Handles an HTTP request. /// Handles an HTTP request.
virtual bool handleHTTPRequest(HttpConnection* connection, const QString& path) = 0; virtual bool handleHTTPRequest(HTTPConnection* connection, const QString& path) = 0;
}; };
/// Handles HTTP connections /// Handles HTTP connections
class HttpManager : public QTcpServer, public HttpRequestHandler { class HTTPManager : public QTcpServer, public HttpRequestHandler {
Q_OBJECT Q_OBJECT
public: public:
/// Initializes the manager. /// Initializes the manager.
HttpManager(quint16 port, const QString& documentRoot, HttpRequestHandler* requestHandler = NULL, QObject* parent = 0); HTTPManager(quint16 port, const QString& documentRoot, HttpRequestHandler* requestHandler = NULL, QObject* parent = 0);
bool handleHTTPRequest(HttpConnection* connection, const QString& path); bool handleHTTPRequest(HTTPConnection* connection, const QString& path);
protected slots: protected slots:
/// Accepts all pending connections /// Accepts all pending connections
@ -40,4 +40,4 @@ protected:
HttpRequestHandler* _requestHandler; HttpRequestHandler* _requestHandler;
}; };
#endif /* defined(__hifi__HttpManager__) */ #endif /* defined(__hifi__HTTPManager__) */