Fork of mbed-http
Fork of mbed-http by
Revision 14:5f9acddaa0a4, committed 2017-03-29
- Comitter:
- Matthew Else
- Date:
- Wed Mar 29 17:26:14 2017 +0100
- Parent:
- 13:efe5c8b16dab
- Commit message:
- Tidy up chunked detection
Changed in this revision
| source/http_request.h | Show annotated file Show diff for this revision Revisions of this file |
| source/http_response.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/source/http_request.h Wed Mar 29 16:52:54 2017 +0100
+++ b/source/http_request.h Wed Mar 29 17:26:14 2017 +0100
@@ -167,7 +167,8 @@
return NULL;
}
- if (response->get_expected_content_length() == 0) {
+ // if we don't get a content-length field in the first chunk, assume it's chunked.
+ if (!response->get_have_content_length()) {
response->set_chunked();
}
--- a/source/http_response.h Wed Mar 29 16:52:54 2017 +0100
+++ b/source/http_response.h Wed Mar 29 17:26:14 2017 +0100
@@ -30,6 +30,7 @@
concat_header_field = false;
concat_header_value = false;
expected_content_length = 0;
+ have_content_length = false;
is_chunked = false;
is_message_completed = false;
body_length = 0;
@@ -64,6 +65,11 @@
void set_header_field(string field) {
concat_header_value = false;
+ if (strcicmp(field.c_str(), "content-length") == 0) {
+ // we have a content-length
+ have_content_length = true;
+ }
+
// headers can be chunked
if (concat_header_field) {
*header_fields[header_fields.size() - 1] = (*header_fields[header_fields.size() - 1]) + field;
@@ -159,8 +165,8 @@
is_message_completed = true;
}
- size_t get_expected_content_length() {
- return expected_content_length;
+ bool get_have_content_length() {
+ return have_content_length;
}
private:
@@ -194,7 +200,7 @@
size_t expected_content_length;
bool is_chunked;
-
+ bool have_content_length;
bool is_message_completed;
char * body;
Matthew Else
