summaryrefslogtreecommitdiffstats
path: root/src/HTTPServer
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-01-03 15:59:55 +0100
committerMattes D <github@xoft.cz>2016-03-01 16:19:56 +0100
commitfea556ca1b8aeec975f5276d5d829ee6275841d9 (patch)
tree9a61a61edbb232c01bfb34e1c2959542d470887e /src/HTTPServer
parentAdded HTTPResponseParser. (diff)
downloadcuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.gz
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.bz2
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.lz
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.xz
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.zst
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.zip
Diffstat (limited to '')
-rw-r--r--src/HTTP/CMakeLists.txt (renamed from src/HTTPServer/CMakeLists.txt)0
-rw-r--r--src/HTTP/EnvelopeParser.cpp (renamed from src/HTTPServer/EnvelopeParser.cpp)0
-rw-r--r--src/HTTP/EnvelopeParser.h (renamed from src/HTTPServer/EnvelopeParser.h)0
-rw-r--r--src/HTTP/HTTPFormParser.cpp (renamed from src/HTTPServer/HTTPFormParser.cpp)0
-rw-r--r--src/HTTP/HTTPFormParser.h (renamed from src/HTTPServer/HTTPFormParser.h)0
-rw-r--r--src/HTTP/HTTPMessage.cpp (renamed from src/HTTPServer/HTTPMessage.cpp)0
-rw-r--r--src/HTTP/HTTPMessage.h (renamed from src/HTTPServer/HTTPMessage.h)0
-rw-r--r--src/HTTP/HTTPRequestParser.cpp (renamed from src/HTTPServer/HTTPRequestParser.cpp)0
-rw-r--r--src/HTTP/HTTPRequestParser.h (renamed from src/HTTPServer/HTTPRequestParser.h)0
-rw-r--r--src/HTTP/HTTPResponseParser.cpp (renamed from src/HTTPServer/HTTPResponseParser.cpp)8
-rw-r--r--src/HTTP/HTTPResponseParser.h (renamed from src/HTTPServer/HTTPResponseParser.h)0
-rw-r--r--src/HTTP/HTTPServer.cpp (renamed from src/HTTPServer/HTTPServer.cpp)0
-rw-r--r--src/HTTP/HTTPServer.h (renamed from src/HTTPServer/HTTPServer.h)0
-rw-r--r--src/HTTP/HTTPServerConnection.cpp (renamed from src/HTTPServer/HTTPServerConnection.cpp)0
-rw-r--r--src/HTTP/HTTPServerConnection.h (renamed from src/HTTPServer/HTTPServerConnection.h)0
-rw-r--r--src/HTTP/MultipartParser.cpp (renamed from src/HTTPServer/MultipartParser.cpp)0
-rw-r--r--src/HTTP/MultipartParser.h (renamed from src/HTTPServer/MultipartParser.h)0
-rw-r--r--src/HTTP/NameValueParser.cpp (renamed from src/HTTPServer/NameValueParser.cpp)0
-rw-r--r--src/HTTP/NameValueParser.h (renamed from src/HTTPServer/NameValueParser.h)0
-rw-r--r--src/HTTP/SslHTTPServerConnection.cpp (renamed from src/HTTPServer/SslHTTPServerConnection.cpp)0
-rw-r--r--src/HTTP/SslHTTPServerConnection.h (renamed from src/HTTPServer/SslHTTPServerConnection.h)0
-rw-r--r--src/HTTP/TransferEncodingParser.h (renamed from src/HTTPServer/TransferEncodingParser.h)0
-rw-r--r--src/HTTP/UrlParser.cpp (renamed from src/HTTPServer/UrlParser.cpp)0
-rw-r--r--src/HTTP/UrlParser.h (renamed from src/HTTPServer/UrlParser.h)0
-rw-r--r--src/HTTPServer/TransferEncodingParser.cpp132
25 files changed, 7 insertions, 133 deletions
diff --git a/src/HTTPServer/CMakeLists.txt b/src/HTTP/CMakeLists.txt
index 4597f6eda..4597f6eda 100644
--- a/src/HTTPServer/CMakeLists.txt
+++ b/src/HTTP/CMakeLists.txt
diff --git a/src/HTTPServer/EnvelopeParser.cpp b/src/HTTP/EnvelopeParser.cpp
index 407e9dcfc..407e9dcfc 100644
--- a/src/HTTPServer/EnvelopeParser.cpp
+++ b/src/HTTP/EnvelopeParser.cpp
diff --git a/src/HTTPServer/EnvelopeParser.h b/src/HTTP/EnvelopeParser.h
index 2fa930539..2fa930539 100644
--- a/src/HTTPServer/EnvelopeParser.h
+++ b/src/HTTP/EnvelopeParser.h
diff --git a/src/HTTPServer/HTTPFormParser.cpp b/src/HTTP/HTTPFormParser.cpp
index ddf87f540..ddf87f540 100644
--- a/src/HTTPServer/HTTPFormParser.cpp
+++ b/src/HTTP/HTTPFormParser.cpp
diff --git a/src/HTTPServer/HTTPFormParser.h b/src/HTTP/HTTPFormParser.h
index fde6df696..fde6df696 100644
--- a/src/HTTPServer/HTTPFormParser.h
+++ b/src/HTTP/HTTPFormParser.h
diff --git a/src/HTTPServer/HTTPMessage.cpp b/src/HTTP/HTTPMessage.cpp
index ca63397dd..ca63397dd 100644
--- a/src/HTTPServer/HTTPMessage.cpp
+++ b/src/HTTP/HTTPMessage.cpp
diff --git a/src/HTTPServer/HTTPMessage.h b/src/HTTP/HTTPMessage.h
index 50b1f9e19..50b1f9e19 100644
--- a/src/HTTPServer/HTTPMessage.h
+++ b/src/HTTP/HTTPMessage.h
diff --git a/src/HTTPServer/HTTPRequestParser.cpp b/src/HTTP/HTTPRequestParser.cpp
index 9c60c6053..9c60c6053 100644
--- a/src/HTTPServer/HTTPRequestParser.cpp
+++ b/src/HTTP/HTTPRequestParser.cpp
diff --git a/src/HTTPServer/HTTPRequestParser.h b/src/HTTP/HTTPRequestParser.h
index f3d3add91..f3d3add91 100644
--- a/src/HTTPServer/HTTPRequestParser.h
+++ b/src/HTTP/HTTPRequestParser.h
diff --git a/src/HTTPServer/HTTPResponseParser.cpp b/src/HTTP/HTTPResponseParser.cpp
index b3ce9dab6..9411208e2 100644
--- a/src/HTTPServer/HTTPResponseParser.cpp
+++ b/src/HTTP/HTTPResponseParser.cpp
@@ -13,6 +13,7 @@
cHTTPResponseParser::cHTTPResponseParser(cHTTPResponseParser::cCallbacks & a_Callbacks):
Super(mkResponse),
m_Callbacks(a_Callbacks),
+ m_HasHadError(false),
m_IsInHeaders(true),
m_IsFinished(false),
m_EnvelopeParser(*this)
@@ -56,7 +57,7 @@ size_t cHTTPResponseParser::Parse(const char * a_Data, size_t a_Size)
if (!m_Buffer.empty())
{
// Headers finished and there's still data left in the buffer, process it as message body:
- m_IsInHeaders = false;
+ HeadersFinished();
return ParseBody(m_Buffer.data(), m_Buffer.size());
}
return 0;
@@ -132,6 +133,10 @@ void cHTTPResponseParser::HeadersFinished(void)
{
m_TransferEncodingParser = cTransferEncodingParser::Create(*this, "identity", m_ContentLength);
}
+ else
+ {
+ m_TransferEncodingParser = cTransferEncodingParser::Create(*this, transferEncoding->second, m_ContentLength);
+ }
}
@@ -169,6 +174,7 @@ void cHTTPResponseParser::OnBodyData(const void * a_Data, size_t a_Size)
void cHTTPResponseParser::OnBodyFinished(void)
{
+ m_IsFinished = true;
m_Callbacks.OnBodyFinished();
}
diff --git a/src/HTTPServer/HTTPResponseParser.h b/src/HTTP/HTTPResponseParser.h
index 19652ccef..19652ccef 100644
--- a/src/HTTPServer/HTTPResponseParser.h
+++ b/src/HTTP/HTTPResponseParser.h
diff --git a/src/HTTPServer/HTTPServer.cpp b/src/HTTP/HTTPServer.cpp
index 741f5f1c5..741f5f1c5 100644
--- a/src/HTTPServer/HTTPServer.cpp
+++ b/src/HTTP/HTTPServer.cpp
diff --git a/src/HTTPServer/HTTPServer.h b/src/HTTP/HTTPServer.h
index 15202a50e..15202a50e 100644
--- a/src/HTTPServer/HTTPServer.h
+++ b/src/HTTP/HTTPServer.h
diff --git a/src/HTTPServer/HTTPServerConnection.cpp b/src/HTTP/HTTPServerConnection.cpp
index 0ee9f3ce7..0ee9f3ce7 100644
--- a/src/HTTPServer/HTTPServerConnection.cpp
+++ b/src/HTTP/HTTPServerConnection.cpp
diff --git a/src/HTTPServer/HTTPServerConnection.h b/src/HTTP/HTTPServerConnection.h
index af2abb73f..af2abb73f 100644
--- a/src/HTTPServer/HTTPServerConnection.h
+++ b/src/HTTP/HTTPServerConnection.h
diff --git a/src/HTTPServer/MultipartParser.cpp b/src/HTTP/MultipartParser.cpp
index 09f4fd02a..09f4fd02a 100644
--- a/src/HTTPServer/MultipartParser.cpp
+++ b/src/HTTP/MultipartParser.cpp
diff --git a/src/HTTPServer/MultipartParser.h b/src/HTTP/MultipartParser.h
index 4f20b2bed..4f20b2bed 100644
--- a/src/HTTPServer/MultipartParser.h
+++ b/src/HTTP/MultipartParser.h
diff --git a/src/HTTPServer/NameValueParser.cpp b/src/HTTP/NameValueParser.cpp
index f759c4d21..f759c4d21 100644
--- a/src/HTTPServer/NameValueParser.cpp
+++ b/src/HTTP/NameValueParser.cpp
diff --git a/src/HTTPServer/NameValueParser.h b/src/HTTP/NameValueParser.h
index e205079db..e205079db 100644
--- a/src/HTTPServer/NameValueParser.h
+++ b/src/HTTP/NameValueParser.h
diff --git a/src/HTTPServer/SslHTTPServerConnection.cpp b/src/HTTP/SslHTTPServerConnection.cpp
index 547e6de3a..547e6de3a 100644
--- a/src/HTTPServer/SslHTTPServerConnection.cpp
+++ b/src/HTTP/SslHTTPServerConnection.cpp
diff --git a/src/HTTPServer/SslHTTPServerConnection.h b/src/HTTP/SslHTTPServerConnection.h
index 6032a2bd0..6032a2bd0 100644
--- a/src/HTTPServer/SslHTTPServerConnection.h
+++ b/src/HTTP/SslHTTPServerConnection.h
diff --git a/src/HTTPServer/TransferEncodingParser.h b/src/HTTP/TransferEncodingParser.h
index ce3d01df7..ce3d01df7 100644
--- a/src/HTTPServer/TransferEncodingParser.h
+++ b/src/HTTP/TransferEncodingParser.h
diff --git a/src/HTTPServer/UrlParser.cpp b/src/HTTP/UrlParser.cpp
index 05db3e413..05db3e413 100644
--- a/src/HTTPServer/UrlParser.cpp
+++ b/src/HTTP/UrlParser.cpp
diff --git a/src/HTTPServer/UrlParser.h b/src/HTTP/UrlParser.h
index 15a63e05d..15a63e05d 100644
--- a/src/HTTPServer/UrlParser.h
+++ b/src/HTTP/UrlParser.h
diff --git a/src/HTTPServer/TransferEncodingParser.cpp b/src/HTTPServer/TransferEncodingParser.cpp
deleted file mode 100644
index 8b703fd42..000000000
--- a/src/HTTPServer/TransferEncodingParser.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-
-// TransferEncodingParser.cpp
-
-// Implements the cTransferEncodingParser class and its descendants representing the parser for the various transfer encodings (chunked etc.)
-
-#include "Globals.h"
-#include "TransferEncodingParser.h"
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// cChunkedTEParser:
-
-class cChunkedTEParser:
- public cTransferEncodingParser
-{
- typedef cTransferEncodingParser Super;
-
-public:
- cChunkedTEParser(cCallbacks & a_Callbacks):
- Super(a_Callbacks),
- m_IsFinished(false)
- {
- }
-
-
-protected:
-
- /** True if the datastream has finished (zero-length chunk received). */
- bool m_IsFinished;
-
-
- // cTransferEncodingParser overrides:
- virtual size_t Parse(const char * a_Data, size_t a_Size) override
- {
- // TODO
- m_Callbacks.OnError("cChunkedTEParser not implemented yet");
- return AString::npos;
- }
-
- virtual void Finish(void) override
- {
- if (!m_IsFinished)
- {
- m_Callbacks.OnError("ChunkedTransferEncoding: Finish signal received before the data stream ended");
- }
- m_IsFinished = true;
- }
-};
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// cIdentityTEParser:
-
-class cIdentityTEParser:
- public cTransferEncodingParser
-{
- typedef cTransferEncodingParser Super;
-
-public:
- cIdentityTEParser(cCallbacks & a_Callbacks, size_t a_ContentLength):
- Super(a_Callbacks),
- m_BytesLeft(a_ContentLength)
- {
- }
-
-
-protected:
- /** How many bytes of content are left before the message ends. */
- size_t m_BytesLeft;
-
- // cTransferEncodingParser overrides:
- virtual size_t Parse(const char * a_Data, size_t a_Size) override
- {
- auto size = std::min(a_Size, m_BytesLeft);
- if (size > 0)
- {
- m_Callbacks.OnBodyData(a_Data, size);
- }
- m_BytesLeft -= size;
- if (m_BytesLeft == 0)
- {
- m_Callbacks.OnBodyFinished();
- }
- return a_Size - size;
- }
-
- virtual void Finish(void) override
- {
- if (m_BytesLeft > 0)
- {
- m_Callbacks.OnError("IdentityTransferEncoding: body was truncated");
- }
- else
- {
- // BodyFinished has already been called, just bail out
- }
- }
-};
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// cTransferEncodingParser:
-
-cTransferEncodingParserPtr cTransferEncodingParser::Create(
- cCallbacks & a_Callbacks,
- const AString & a_TransferEncoding,
- size_t a_ContentLength
-)
-{
- if (a_TransferEncoding == "chunked")
- {
- return std::make_shared<cChunkedTEParser>(a_Callbacks);
- }
- if (a_TransferEncoding.empty())
- {
- return std::make_shared<cIdentityTEParser>(a_Callbacks, a_ContentLength);
- }
- return nullptr;
-}
-
-
-
-