summaryrefslogtreecommitdiffstats
path: root/source/HTTPServer/HTTPConnection.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-10-04 13:07:57 +0200
committermadmaxoft <github@xoft.cz>2013-10-04 13:13:34 +0200
commit1012fd82fda9e9bc75d2308a3c68cb3b3738bf1b (patch)
treec03e55ed3e05de4d771510d9249a4bbdef1bf26e /source/HTTPServer/HTTPConnection.cpp
parentFixed MultiPartParser's boundary parsing. (diff)
downloadcuberite-1012fd82fda9e9bc75d2308a3c68cb3b3738bf1b.tar
cuberite-1012fd82fda9e9bc75d2308a3c68cb3b3738bf1b.tar.gz
cuberite-1012fd82fda9e9bc75d2308a3c68cb3b3738bf1b.tar.bz2
cuberite-1012fd82fda9e9bc75d2308a3c68cb3b3738bf1b.tar.lz
cuberite-1012fd82fda9e9bc75d2308a3c68cb3b3738bf1b.tar.xz
cuberite-1012fd82fda9e9bc75d2308a3c68cb3b3738bf1b.tar.zst
cuberite-1012fd82fda9e9bc75d2308a3c68cb3b3738bf1b.zip
Diffstat (limited to 'source/HTTPServer/HTTPConnection.cpp')
-rw-r--r--source/HTTPServer/HTTPConnection.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/source/HTTPServer/HTTPConnection.cpp b/source/HTTPServer/HTTPConnection.cpp
index c36b07d3d..61f4b3a31 100644
--- a/source/HTTPServer/HTTPConnection.cpp
+++ b/source/HTTPServer/HTTPConnection.cpp
@@ -108,22 +108,13 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size)
{
case wcsRecvHeaders:
{
- ASSERT(m_CurrentRequest == NULL);
-
- // Start searching 3 chars from the end of the already received data, if available:
- size_t SearchStart = m_IncomingHeaderData.size();
- SearchStart = (SearchStart > 3) ? SearchStart - 3 : 0;
-
- m_IncomingHeaderData.append(a_Data, a_Size);
-
- // Parse the header, if it is complete:
- size_t idxEnd = m_IncomingHeaderData.find("\r\n\r\n", SearchStart);
- if (idxEnd == AString::npos)
+ if (m_CurrentRequest == NULL)
{
- return;
+ m_CurrentRequest = new cHTTPRequest;
}
- m_CurrentRequest = new cHTTPRequest;
- if (!m_CurrentRequest->ParseHeaders(m_IncomingHeaderData.c_str(), idxEnd + 2))
+
+ int BytesConsumed = m_CurrentRequest->ParseHeaders(a_Data, a_Size);
+ if (BytesConsumed < 0)
{
delete m_CurrentRequest;
m_CurrentRequest = NULL;
@@ -131,20 +122,29 @@ void cHTTPConnection::DataReceived(const char * a_Data, int a_Size)
m_HTTPServer.CloseConnection(*this);
return;
}
+ if (m_CurrentRequest->IsInHeaders())
+ {
+ // The request headers are not yet complete
+ return;
+ }
+
+ // The request has finished parsing its headers successfully, notify of it:
m_State = wcsRecvBody;
m_HTTPServer.NewRequest(*this, *m_CurrentRequest);
m_CurrentRequestBodyRemaining = m_CurrentRequest->GetContentLength();
+ if (m_CurrentRequestBodyRemaining < 0)
+ {
+ // The body length was not specified in the request, assume zero
+ m_CurrentRequestBodyRemaining = 0;
+ }
// Process the rest of the incoming data into the request body:
- if (m_IncomingHeaderData.size() > idxEnd + 4)
+ if (a_Size > BytesConsumed)
{
- m_IncomingHeaderData.erase(0, idxEnd + 4);
- DataReceived(m_IncomingHeaderData.c_str(), m_IncomingHeaderData.size());
- m_IncomingHeaderData.clear();
+ DataReceived(a_Data + BytesConsumed, a_Size - BytesConsumed);
}
else
{
- m_IncomingHeaderData.clear();
DataReceived("", 0); // If the request has zero body length, let it be processed right-away
}
break;