Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr 499 #578

Merged
merged 2 commits into from
Jan 31, 2016
Merged
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
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