diff --git a/examples/simple/simple.cpp b/examples/simple/simple.cpp index 780bfb8..612c7e7 100644 --- a/examples/simple/simple.cpp +++ b/examples/simple/simple.cpp @@ -2,10 +2,11 @@ #include "HttpServer.h" #include "HttpHandler.h" #include "HttpConnection.h" +#include static const QByteArray someHeaderToken("Some-Header"); static const QString someParam("Some-Param"); -static const QByteArray helloWorldToken("Hello World!"); +static const QString dataParamName("data"); class SimpleExerciser : public Pillow::HttpHandler { @@ -16,6 +17,7 @@ class SimpleExerciser : public Pillow::HttpHandler bool handleRequest(Pillow::HttpConnection *connection) { + QByteArray helloWorldToken("Hello World!"); n += connection->requestContent().size(); n += connection->requestFragment().size(); n += connection->requestHeaderValue(someHeaderToken).size(); @@ -28,7 +30,12 @@ class SimpleExerciser : public Pillow::HttpHandler n += connection->requestPathDecoded().size(); n += connection->requestQueryStringDecoded().size(); n += connection->requestParamValue(someParam).size(); - connection->writeResponse(200, Pillow::HttpHeaderCollection(), helloWorldToken); + + QTextStream out(stdout); + QString dataVal = connection->requestParamValue(dataParamName); + out << "data val:" << dataVal <writeResponse(200, Pillow::HttpHeaderCollection(), helloWorldToken.append("\r\ndata param val:").append(dataVal)); return true; } }; @@ -42,12 +49,13 @@ int main(int argc, char *argv[]) exit(1); qDebug() << "Ready"; - Pillow::HttpHandler* handler = new Pillow::HttpHandlerFixed(200, "", &server); +// Pillow::HttpHandler* handler = new Pillow::HttpHandlerFixed(200, "", &server); // Pillow::HttpHandler* handler = new SimpleExerciser(&server); -// Pillow::HttpHandler* handler = new Pillow::HttpHandlerStack(&server); -// new Pillow::HttpHandlerLog(handler); + Pillow::HttpHandler* handler = new Pillow::HttpHandlerStack(&server); + new Pillow::HttpHandlerLog(handler); + new SimpleExerciser(handler); // new Pillow::HttpHandlerFixed(200, "Hello from pillow!", handler); QObject::connect(&server, SIGNAL(requestReady(Pillow::HttpConnection*)), handler, SLOT(handleRequest(Pillow::HttpConnection*))); diff --git a/pillowcore/HttpConnection.cpp b/pillowcore/HttpConnection.cpp index 3ac43a1..d218184 100644 --- a/pillowcore/HttpConnection.cpp +++ b/pillowcore/HttpConnection.cpp @@ -731,11 +731,15 @@ const QByteArray & Pillow::HttpConnection::requestHeaderValue(const QByteArray & const Pillow::HttpParamCollection& Pillow::HttpConnection::requestParams() { - if (d_ptr->_requestParams.isEmpty() && !d_ptr->_requestQueryString.isEmpty()) + Pillow::ByteArray reqestParamData = d_ptr->_requestQueryString; + if(d_ptr->_requestMethod.toStdString() == "POST"){ + reqestParamData = d_ptr->_requestContent; + } + if (d_ptr->_requestParams.isEmpty() && !reqestParamData.isEmpty()) { // The params have not yet been initialized. Parse them. const char paramDelimiter = '&', keyValueDelimiter = '='; - for (const char* c = d_ptr->_requestQueryString.constBegin(), *cE = d_ptr->_requestQueryString.constEnd(); c < cE;) + for (const char* c = reqestParamData.constBegin(), *cE = reqestParamData.constEnd(); c < cE;) { const char *paramEnd, *keyEnd; for (paramEnd = c; paramEnd < cE; ++paramEnd) if (*paramEnd == paramDelimiter) break; // Find the param delimiter, or the end of string. diff --git a/pillowcore/HttpHandler.cpp b/pillowcore/HttpHandler.cpp index 6fa9dfc..ca822e6 100644 --- a/pillowcore/HttpHandler.cpp +++ b/pillowcore/HttpHandler.cpp @@ -157,7 +157,7 @@ bool HttpHandlerLog::handleRequest(Pillow::HttpConnection *connection) { QString logEntry = QString("[BEGIN] %1 - - [%2] \"%3 %4 %5\" - - -") .arg(connection->remoteAddress().toString()) - .arg(QDateTime::currentDateTime().toString("dd/MMM/yyyy hh:mm:ss")) + .arg(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss")) .arg(QString(connection->requestMethod())).arg(QString(connection->requestUri())).arg(QString(connection->requestHttpVersion())); log(logEntry); @@ -176,7 +176,7 @@ void HttpHandlerLog::requestCompleted(Pillow::HttpConnection *connection) qint64 elapsed = timer->elapsed(); QString logEntry = QString(formatString) .arg(connection->remoteAddress().toString()) - .arg(QDateTime::currentDateTime().toString("dd/MMM/yyyy hh:mm:ss")) + .arg(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss")) .arg(QString(connection->requestMethod())).arg(QString(connection->requestUri())).arg(QString(connection->requestHttpVersion())) .arg(connection->responseStatusCode()).arg(connection->responseContentLength()) .arg(elapsed / 1000.0, 3, 'f', 3); @@ -195,7 +195,7 @@ void HttpHandlerLog::requestClosed(HttpConnection *connection) qint64 elapsed = timer->elapsed(); QString logEntry = QString(formatString) .arg(connection->remoteAddress().toString()) - .arg(QDateTime::currentDateTime().toString("dd/MMM/yyyy hh:mm:ss")) + .arg(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss")) .arg(QString(connection->requestMethod())).arg(QString(connection->requestUri())).arg(QString(connection->requestHttpVersion())) .arg(connection->responseStatusCode()).arg(connection->responseContentLength()) .arg(elapsed / 1000.0, 3, 'f', 3);