From 89907136faf38f0e6edf04c0dcf2dc1b9adb25d9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 2 Oct 2014 10:15:12 -0700 Subject: [PATCH 1/4] one more debug line for script redirect --- domain-server/src/DomainServer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 8f93c7a13e..8b8874c73b 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1089,6 +1089,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url scriptURL.setPath(URI_ASSIGNMENT + "/scripts/" + uuidStringWithoutCurlyBraces(pendingData->getAssignmentUUID())); + qDebug() << "Serving" << scriptURL << "for assignment with ID" << matchingUUID; + // have the HTTPManager serve the appropriate script file return _httpManager.handleHTTPRequest(connection, scriptURL); } From 157fdf6afaeb5275f2660ac5bbaec2eb8cc883ce Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 2 Oct 2014 10:17:31 -0700 Subject: [PATCH 2/4] cleanup debug for script path --- domain-server/src/DomainServer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 8b8874c73b..c4ae5c08f3 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1089,7 +1089,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url scriptURL.setPath(URI_ASSIGNMENT + "/scripts/" + uuidStringWithoutCurlyBraces(pendingData->getAssignmentUUID())); - qDebug() << "Serving" << scriptURL << "for assignment with ID" << matchingUUID; + qDebug() << "Serving" << scriptURL.toString() << "for assignment with ID" + << uuidStringWithoutCurlyBraces(matchingUUID); // have the HTTPManager serve the appropriate script file return _httpManager.handleHTTPRequest(connection, scriptURL); From 4749fdb0bae20d12b5d531e93f666be615ae3e1c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 2 Oct 2014 10:38:46 -0700 Subject: [PATCH 3/4] allow calls to HTTPManager to skip the subHandler and ask for direct processing --- domain-server/src/DomainServer.cpp | 12 +++++------- domain-server/src/DomainServer.h | 4 ++-- libraries/embedded-webserver/src/HTTPManager.cpp | 4 ++-- libraries/embedded-webserver/src/HTTPManager.h | 4 ++-- libraries/embedded-webserver/src/HTTPSManager.cpp | 8 ++++---- libraries/embedded-webserver/src/HTTPSManager.h | 6 +++--- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index c4ae5c08f3..786fd58d61 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1053,10 +1053,11 @@ QString pathForAssignmentScript(const QUuid& assignmentUUID) { return newPath; } -bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url) { +bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) { const QString JSON_MIME_TYPE = "application/json"; const QString URI_ASSIGNMENT = "/assignment"; + const QString URI_ASSIGNMENT_SCRIPTS = URI_ASSIGNMENT + "/scripts"; const QString URI_NODES = "/nodes"; const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; @@ -1067,7 +1068,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url } // check if this is a request for a scripted assignment (with a temp unique UUID) - const QString ASSIGNMENT_REGEX_STRING = QString("\\%1\\/(%2)\\/?$").arg(URI_ASSIGNMENT).arg(UUID_REGEX_STRING); + const QString ASSIGNMENT_REGEX_STRING = QString("\\%1\\/(%2)\\/?$").arg(URI_ASSIGNMENT).arg(UUID_REGEX_STRING); QRegExp assignmentRegex(ASSIGNMENT_REGEX_STRING); if (connection->requestOperation() == QNetworkAccessManager::GetOperation @@ -1089,11 +1090,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url scriptURL.setPath(URI_ASSIGNMENT + "/scripts/" + uuidStringWithoutCurlyBraces(pendingData->getAssignmentUUID())); - qDebug() << "Serving" << scriptURL.toString() << "for assignment with ID" - << uuidStringWithoutCurlyBraces(matchingUUID); - // have the HTTPManager serve the appropriate script file - return _httpManager.handleHTTPRequest(connection, scriptURL); + return _httpManager.handleHTTPRequest(connection, scriptURL, true); } } } @@ -1327,7 +1325,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url const QString HIFI_SESSION_COOKIE_KEY = "DS_WEB_SESSION_UUID"; -bool DomainServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl &url) { +bool DomainServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl &url, bool skipSubHandler) { const QString URI_OAUTH = "/oauth"; qDebug() << "HTTPS request received at" << url.toString(); if (url.path() == URI_OAUTH) { diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 44b8a15901..57d62291bd 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -43,8 +43,8 @@ public: static int const EXIT_CODE_REBOOT; - bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url); - bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url); + bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false); + bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler = false); public slots: /// Called by NodeList to inform us a node has been added diff --git a/libraries/embedded-webserver/src/HTTPManager.cpp b/libraries/embedded-webserver/src/HTTPManager.cpp index ec5f16012e..702d709f72 100755 --- a/libraries/embedded-webserver/src/HTTPManager.cpp +++ b/libraries/embedded-webserver/src/HTTPManager.cpp @@ -40,8 +40,8 @@ void HTTPManager::incomingConnection(qintptr socketDescriptor) { } } -bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QUrl& url) { - if (requestHandledByRequestHandler(connection, url)) { +bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) { + if (!skipSubHandler && requestHandledByRequestHandler(connection, url)) { // this request was handled by our request handler object // so we don't need to attempt to do so in the document root return true; diff --git a/libraries/embedded-webserver/src/HTTPManager.h b/libraries/embedded-webserver/src/HTTPManager.h index e8745521dc..83c4103c15 100755 --- a/libraries/embedded-webserver/src/HTTPManager.h +++ b/libraries/embedded-webserver/src/HTTPManager.h @@ -24,7 +24,7 @@ class HTTPSConnection; class HTTPRequestHandler { public: /// Handles an HTTP request. - virtual bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url) = 0; + virtual bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false) = 0; }; /// Handles HTTP connections @@ -34,7 +34,7 @@ public: /// Initializes the manager. HTTPManager(quint16 port, const QString& documentRoot, HTTPRequestHandler* requestHandler = NULL, QObject* parent = 0); - bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url); + bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false); protected: /// Accepts all pending connections diff --git a/libraries/embedded-webserver/src/HTTPSManager.cpp b/libraries/embedded-webserver/src/HTTPSManager.cpp index 4e40a0e02c..94e1a35e20 100644 --- a/libraries/embedded-webserver/src/HTTPSManager.cpp +++ b/libraries/embedded-webserver/src/HTTPSManager.cpp @@ -38,12 +38,12 @@ void HTTPSManager::incomingConnection(qintptr socketDescriptor) { } } -bool HTTPSManager::handleHTTPRequest(HTTPConnection* connection, const QUrl &url) { - return handleHTTPSRequest(reinterpret_cast(connection), url); +bool HTTPSManager::handleHTTPRequest(HTTPConnection* connection, const QUrl &url, bool skipSubHandler) { + return handleHTTPSRequest(reinterpret_cast(connection), url, skipSubHandler); } -bool HTTPSManager::handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url) { - return HTTPManager::handleHTTPRequest(connection, url); +bool HTTPSManager::handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler) { + return HTTPManager::handleHTTPRequest(connection, url, skipSubHandler); } bool HTTPSManager::requestHandledByRequestHandler(HTTPConnection* connection, const QUrl& url) { diff --git a/libraries/embedded-webserver/src/HTTPSManager.h b/libraries/embedded-webserver/src/HTTPSManager.h index fe7c4dc065..66c0c76d0b 100644 --- a/libraries/embedded-webserver/src/HTTPSManager.h +++ b/libraries/embedded-webserver/src/HTTPSManager.h @@ -20,7 +20,7 @@ class HTTPSRequestHandler : public HTTPRequestHandler { public: /// Handles an HTTPS request - virtual bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url) = 0; + virtual bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler = false) = 0; }; class HTTPSManager : public HTTPManager, public HTTPSRequestHandler { @@ -35,8 +35,8 @@ public: void setCertificate(const QSslCertificate& certificate) { _certificate = certificate; } void setPrivateKey(const QSslKey& privateKey) { _privateKey = privateKey; } - bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url); - bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url); + bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false); + bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler = false); protected: void incomingConnection(qintptr socketDescriptor); From 60e3f3edfaffed8784df239364afcc7b9cb05b12 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 2 Oct 2014 11:20:54 -0700 Subject: [PATCH 4/4] add skipSubHandler to OctreeServer HTTPRequestHandler calls --- assignment-client/src/octree/OctreeServer.cpp | 2 +- assignment-client/src/octree/OctreeServer.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 23e8c0d965..5833d8a764 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -302,7 +302,7 @@ void OctreeServer::initHTTPManager(int port) { _httpManager = new HTTPManager(port, documentRoot, this, this); } -bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url) { +bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) { #ifdef FORCE_CRASH if (connection->requestOperation() == QNetworkAccessManager::GetOperation diff --git a/assignment-client/src/octree/OctreeServer.h b/assignment-client/src/octree/OctreeServer.h index fda3187892..aa0c419dd4 100644 --- a/assignment-client/src/octree/OctreeServer.h +++ b/assignment-client/src/octree/OctreeServer.h @@ -115,7 +115,7 @@ public: static int howManyThreadsDidHandlePacketSend(quint64 since = 0); static int howManyThreadsDidCallWriteDatagram(quint64 since = 0); - bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url); + bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler); virtual void aboutToFinish(); void forceNodeShutdown(SharedNodePointer node);