fix the problem http request with '\0' and fixx query string in url
Fork of mbed-http by
Revision 4:539df159e058, committed 2017-02-23
- Comitter:
- Jan Jongboom
- Date:
- Thu Feb 23 13:50:43 2017 +0100
- Parent:
- 3:8a6b003e3874
- Child:
- 5:2456c90f02e9
- Commit message:
- Allocate body on the heap, not on the stack
Changed in this revision
| source/http_response.h | Show annotated file Show diff for this revision Revisions of this file |
| source/http_response_parser.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/source/http_response.h Thu Feb 23 13:28:07 2017 +0100
+++ b/source/http_response.h Thu Feb 23 13:50:43 2017 +0100
@@ -31,6 +31,14 @@
concat_header_value = false;
expected_content_length = 0;
body_length = 0;
+ body_offset = 0;
+ body = NULL;
+ }
+
+ ~HttpResponse() {
+ if (body != NULL) {
+ free(body);
+ }
}
void set_status(int a_status_code, string a_status_message) {
@@ -96,18 +104,34 @@
return header_values;
}
- void set_body(string v) {
- body = body + v;
+ void set_body(const char *at, size_t length) {
+ // only malloc when this fn is called, so we don't alloc when body callback's are enabled
+ if (body == NULL) {
+ body = (char*)malloc(expected_content_length);
+ }
+
+ memcpy(body + body_offset, at, length);
+
+ body_offset += length;
}
- string get_body() {
- return body;
+ void* get_body() {
+ return (void*)body;
+ }
+
+ string get_body_as_string() {
+ string s(body, body_offset);
+ return s;
}
void increase_body_length(size_t length) {
body_length += length;
}
+ size_t get_body_length() {
+ return body_offset;
+ }
+
bool is_body_complete() {
return body_length == expected_content_length;
}
@@ -134,7 +158,8 @@
size_t expected_content_length;
- string body;
+ char * body;
size_t body_length;
+ size_t body_offset;
};
#endif
--- a/source/http_response_parser.h Thu Feb 23 13:28:07 2017 +0100
+++ b/source/http_response_parser.h Thu Feb 23 13:50:43 2017 +0100
@@ -103,8 +103,7 @@
return 0;
}
- string s(at, length);
- response->set_body(s);
+ response->set_body(at, length);
return 0;
}
