diff --git a/Sming/SmingCore/Network/HttpRequest.cpp b/Sming/SmingCore/Network/HttpRequest.cpp index 36c63b193a..f0d9e9bcc8 100644 --- a/Sming/SmingCore/Network/HttpRequest.cpp +++ b/Sming/SmingCore/Network/HttpRequest.cpp @@ -19,6 +19,7 @@ HttpRequest::HttpRequest() cookies = NULL; postDataProcessed = 0; combinePostFrag = false; + bodyBuf = NULL; } HttpRequest::~HttpRequest() @@ -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 /* = "" */) @@ -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() { diff --git a/Sming/SmingCore/Network/HttpRequest.h b/Sming/SmingCore/Network/HttpRequest.h index 9317522eba..ef444af857 100644 --- a/Sming/SmingCore/Network/HttpRequest.h +++ b/Sming/SmingCore/Network/HttpRequest.h @@ -42,6 +42,7 @@ 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); @@ -49,6 +50,7 @@ class HttpRequest bool extractParsingItemsList(pbuf* buf, int startPos, int endPos, char delimChar, char endChar, HashMap *resultItems); + void parseRawData(HttpServer *server, pbuf* buf); private: String method; @@ -59,6 +61,7 @@ class HttpRequest HashMap *cookies; int postDataProcessed; bool combinePostFrag; + char *bodyBuf; friend class TemplateFileStream; }; diff --git a/Sming/SmingCore/Network/HttpServerConnection.cpp b/Sming/SmingCore/Network/HttpServerConnection.cpp index 9a7261d423..022c44c256 100644 --- a/Sming/SmingCore/Network/HttpServerConnection.cpp +++ b/Sming/SmingCore/Network/HttpServerConnection.cpp @@ -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) @@ -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);