summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-08-24 08:28:44 +0200
committerMattes D <github@xoft.cz>2016-08-24 08:28:44 +0200
commitc45bd4b968392eeeed3954d6b91dec7ae5833a0d (patch)
tree53c5a6a97c2a2ce8ec5c4984edbc855d396cd3b6
parentMerge pull request #3310 from cuberite/UrlClient (diff)
downloadcuberite-c45bd4b968392eeeed3954d6b91dec7ae5833a0d.tar
cuberite-c45bd4b968392eeeed3954d6b91dec7ae5833a0d.tar.gz
cuberite-c45bd4b968392eeeed3954d6b91dec7ae5833a0d.tar.bz2
cuberite-c45bd4b968392eeeed3954d6b91dec7ae5833a0d.tar.lz
cuberite-c45bd4b968392eeeed3954d6b91dec7ae5833a0d.tar.xz
cuberite-c45bd4b968392eeeed3954d6b91dec7ae5833a0d.tar.zst
cuberite-c45bd4b968392eeeed3954d6b91dec7ae5833a0d.zip
Diffstat (limited to '')
-rw-r--r--src/HTTP/EnvelopeParser.cpp9
-rw-r--r--tests/HTTP/CMakeLists.txt13
-rw-r--r--tests/HTTP/HTTPRequest1.data3
-rw-r--r--tests/HTTP/HTTPResponse1.data1
-rw-r--r--tests/HTTP/HTTPResponse2.data1
5 files changed, 25 insertions, 2 deletions
diff --git a/src/HTTP/EnvelopeParser.cpp b/src/HTTP/EnvelopeParser.cpp
index 1c49b643f..15ab95380 100644
--- a/src/HTTP/EnvelopeParser.cpp
+++ b/src/HTTP/EnvelopeParser.cpp
@@ -118,7 +118,14 @@ bool cEnvelopeParser::ParseLine(const char * a_Data, size_t a_Size)
if (a_Data[i] == ':')
{
m_LastKey.assign(a_Data, i);
- m_LastValue.assign(a_Data + i + 2, a_Size - i - 2);
+ if (a_Size > i + 1)
+ {
+ m_LastValue.assign(a_Data + i + 2, a_Size - i - 2);
+ }
+ else
+ {
+ m_LastValue.clear();
+ }
return true;
}
} // for i - a_Data[]
diff --git a/tests/HTTP/CMakeLists.txt b/tests/HTTP/CMakeLists.txt
index cb2329adc..04e82caf9 100644
--- a/tests/HTTP/CMakeLists.txt
+++ b/tests/HTTP/CMakeLists.txt
@@ -44,11 +44,22 @@ endif()
+set (TEST_DATA_FILES
+ HTTPRequest1.data
+ HTTPRequest2.data
+ HTTPResponse1.data
+ HTTPResponse2.data
+)
+
+source_group("Data Files" FILES ${TEST_DATA_FILES})
+
+
+
# Define individual test executables:
# HTTPMessageParser_file: Feed file contents into a cHTTPResponseParser and print the callbacks as they're called:
-add_executable(HTTPMessageParser_file-exe HTTPMessageParser_file.cpp)
+add_executable(HTTPMessageParser_file-exe HTTPMessageParser_file.cpp ${TEST_DATA_FILES})
target_link_libraries(HTTPMessageParser_file-exe HTTP Network OSSupport)
# UrlClientTest: Tests the UrlClient class by requesting a few things off the internet:
diff --git a/tests/HTTP/HTTPRequest1.data b/tests/HTTP/HTTPRequest1.data
index cac43c06c..cdfb7f7fb 100644
--- a/tests/HTTP/HTTPRequest1.data
+++ b/tests/HTTP/HTTPRequest1.data
@@ -1,5 +1,8 @@
GET /some/url HTTP/1.1
Note: This is a test of a regular request
Content-Length: 3
+Empty-Header:
+Almost-Empty-Header: a
+Two-Char-Header: 12
bla \ No newline at end of file
diff --git a/tests/HTTP/HTTPResponse1.data b/tests/HTTP/HTTPResponse1.data
index 97e0b23c3..f6eb47217 100644
--- a/tests/HTTP/HTTPResponse1.data
+++ b/tests/HTTP/HTTPResponse1.data
@@ -6,5 +6,6 @@ Note3: The data is 2 bytes longer than the actual request, parser should indicat
Header1: Value1
Header2: Value2
Content-Length: 3
+Empty-Header:
bla
diff --git a/tests/HTTP/HTTPResponse2.data b/tests/HTTP/HTTPResponse2.data
index d708c4758..cb8dde4a2 100644
--- a/tests/HTTP/HTTPResponse2.data
+++ b/tests/HTTP/HTTPResponse2.data
@@ -2,6 +2,7 @@ HTTP/1.0 200 OK
Note: This is a Chunked transfer encoding test
Header2: Value2
Transfer-Encoding: chunked
+Empty-Header:
4
Wiki