Skip to content

Commit

Permalink
Merge pull request #578 from SmingHub/PR_499
Browse files Browse the repository at this point in the history
Pr 499
  • Loading branch information
hreintke committed Jan 31, 2016
2 parents bb231fe + 6df2b54 commit f52d8ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Sming/SmingCore/Network/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ HttpRequest::HttpRequest()
cookies = NULL;
postDataProcessed = 0;
combinePostFrag = false;
bodyBuf = NULL;
}

HttpRequest::~HttpRequest()
Expand All @@ -28,6 +29,10 @@ HttpRequest::~HttpRequest()
delete requestPostParameters;
delete cookies;
postDataProcessed = 0;
if (bodyBuf != NULL)
{
os_free(bodyBuf);
}
}

String HttpRequest::getQueryParameter(String parameterName, String defaultValue /* = "" */)
Expand Down Expand Up @@ -229,6 +234,22 @@ bool HttpRequest::extractParsingItemsList(pbuf* buf, int startPos, int endPos, c
}
return continued;
}
void HttpRequest::parseRawData(HttpServer *server, pbuf* buf)
{
bodyBuf = (char *) os_zalloc(sizeof(char) * buf->tot_len);
int headerEnd = NetUtils::pbufFindStr(buf, "\r\n\r\n");
if (headerEnd + getContentLength() > NETWORK_MAX_HTTP_PARSING_LEN)
{
debugf("NETWORK_MAX_HTTP_PARSING_LEN");
return;
}
pbuf_copy_partial(buf, bodyBuf, buf->tot_len, headerEnd + 4);
}

char* HttpRequest::getBody()
{
return bodyBuf;
}

bool HttpRequest::isAjax()
{
Expand Down
3 changes: 3 additions & 0 deletions Sming/SmingCore/Network/HttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ class HttpRequest
String getPostParameter(String parameterName, String defaultValue = "");
String getHeader(String headerName, String defaultValue = "");
String getCookie(String cookieName, String defaultValue = "");
char* getBody();

public:
HttpParseResult parseHeader(HttpServer *server, pbuf* buf);
HttpParseResult parsePostData(HttpServer *server, pbuf* buf);
bool extractParsingItemsList(pbuf* buf, int startPos, int endPos,
char delimChar, char endChar,
HashMap<String, String> *resultItems);
void parseRawData(HttpServer *server, pbuf* buf);

private:
String method;
Expand All @@ -59,6 +61,7 @@ class HttpRequest
HashMap<String, String> *cookies;
int postDataProcessed;
bool combinePostFrag;
char *bodyBuf;

friend class TemplateFileStream;
};
Expand Down
10 changes: 9 additions & 1 deletion Sming/SmingCore/Network/HttpServerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ err_t HttpServerConnection::onReceive(pbuf *buf)
if (request.getContentLength() > 0 && contType.indexOf(ContentType::FormUrlEncoded) != -1)
state = eHCS_ParsePostData;
else
{
request.parseRawData(server, buf);
state = eHCS_ParsingCompleted;
TcpConnection::onReceive(buf);
return ERR_OK;
}
}
}
else if (state == eHCS_WebSocketFrames)
Expand All @@ -86,7 +91,10 @@ err_t HttpServerConnection::onReceive(pbuf *buf)
state = eHCS_ParsingCompleted;
}
}

// else if (state == eHCS_ParsingCompleted && request.getContentLength() > 0)
// {
// request.parseRawData(server, buf);
// }
// Fire callbacks
TcpConnection::onReceive(buf);

Expand Down

0 comments on commit f52d8ae

Please sign in to comment.