Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions examples/simple/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#include "HttpServer.h"
#include "HttpHandler.h"
#include "HttpConnection.h"
#include <QTextStream>

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
{
Expand All @@ -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();
Expand All @@ -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 <<endl;

connection->writeResponse(200, Pillow::HttpHeaderCollection(), helloWorldToken.append("\r\ndata param val:").append(dataVal));
return true;
}
};
Expand All @@ -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*)));
Expand Down
8 changes: 6 additions & 2 deletions pillowcore/HttpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pillowcore/HttpHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down