Skip to content

Commit

Permalink
Merge pull request #1163 from slaff/tuning/httpserver-default-settings
Browse files Browse the repository at this point in the history
HttpServer: Fixes and tuning
  • Loading branch information
alonewolfx2 committed Jun 26, 2017
2 parents d870c27 + fab7b5b commit 28c8985
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Sming/SmingCore/DataSourceStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ class TemplateFileStream : public FileStream
*/
inline TemplateVariables& variables() { return templateData; }

/**
* @brief Return the total length of the stream
* @retval int -1 is returned when the size cannot be determined
*/
int length() { return -1; }

private:
TemplateVariables templateData;
TemplateExpandState state;
Expand Down
10 changes: 10 additions & 0 deletions Sming/SmingCore/Network/Http/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ HttpRequest* HttpRequest::onRequestComplete(RequestCompletedDelegate delegateFun
return this;
}

void HttpRequest::reset()
{
headers.clear();
postParams.clear();
if(queryParams != NULL) {
delete queryParams;
queryParams = NULL;
}
}

#ifndef SMING_RELEASE
String HttpRequest::toString() {
String content = "";
Expand Down
2 changes: 2 additions & 0 deletions Sming/SmingCore/Network/Http/HttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class HttpRequest {
HttpRequest* onBody(RequestBodyDelegate delegateFunction);
HttpRequest* onRequestComplete(RequestCompletedDelegate delegateFunction);

void reset();

#ifndef SMING_RELEASE
/**
* @brief Tries to present a readable version of the current request values
Expand Down
8 changes: 8 additions & 0 deletions Sming/SmingCore/Network/Http/HttpResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,11 @@ bool HttpResponse::sendDataStream( IDataSourceStream * newDataStream , String re
return true;
}

void HttpResponse::reset()
{
headers.clear();
if(stream != NULL) {
delete stream;
stream = NULL;
}
}
2 changes: 2 additions & 0 deletions Sming/SmingCore/Network/Http/HttpResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class HttpResponse {
// Send Datastream, can be called with Classes derived from
bool sendDataStream( IDataSourceStream * newDataStream , String reqContentType = "" );

void reset();

public:
int code;
HttpHeaders headers;
Expand Down
10 changes: 10 additions & 0 deletions Sming/SmingCore/Network/Http/HttpServerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ int HttpServerConnection::staticOnHeadersComplete(http_parser* parser)
int error = 0;
connection->request.setHeaders(connection->requestHeaders);

connection->lastWasValue = true;
connection->lastData = "";
connection->currentField = "";
connection->requestHeaders.clear();

if(connection->resource != NULL && connection->resource->onHeadersComplete) {
error = connection->resource->onHeadersComplete(*connection, connection->request, connection->response);
}
Expand Down Expand Up @@ -406,6 +411,11 @@ void HttpServerConnection::onReadyToSendData(TcpConnectionEvent sourceEvent)
setTimeOut(1); // decrease the timeout to 1 tick
}

if(state == eHCS_Sent) {
response.reset();
request.reset();
}

TcpClient::onReadyToSendData(sourceEvent);
}

Expand Down
2 changes: 1 addition & 1 deletion Sming/SmingCore/Network/Http/HttpServerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class HttpServerConnection: public TcpClient
String lastData = "";
String currentField = "";

BodyParsers* bodyParsers;
BodyParsers* bodyParsers = NULL;
HttpBodyParserDelegate bodyParser;
};

Expand Down
2 changes: 1 addition & 1 deletion Sming/SmingCore/Network/HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

HttpServer::HttpServer()
{
settings.keepAliveSeconds = 10;
settings.keepAliveSeconds = 0;
configure(settings);
}

Expand Down
2 changes: 1 addition & 1 deletion Sming/SmingCore/Network/HttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

typedef struct {
int maxActiveConnections = 10; // << the maximum number of concurrent requests..
int keepAliveSeconds = 5; // << the default seconds to keep the connection alive before closing it
int keepAliveSeconds = 0; // << the default seconds to keep the connection alive before closing it
int minHeapSize = -1; // << defines the min heap size that is required to accept connection.
// -1 - means use server default
bool useDefaultBodyParsers = 1; // << if the default body parsers, as form-url-encoded, should be used
Expand Down

0 comments on commit 28c8985

Please sign in to comment.