diff --git a/modules/web/http_server_simple/http_parser.cpp b/modules/web/http_server_simple/http_parser.cpp index 895a26e26..355813b2a 100644 --- a/modules/web/http_server_simple/http_parser.cpp +++ b/modules/web/http_server_simple/http_parser.cpp @@ -248,6 +248,40 @@ void HTTPParser::_process_multipart_header(const String &header) { } } +void HTTPParser::process_urlenc_data() { + if (_partial_data == "") { + return; + } + + Vector params = _partial_data.split("&", false); + + for (int i = 0; i < params.size(); ++i) { + String p = params[i]; + + //Ignore if it has no, or more than one = + const CharType *c = p.ptr(); + int eqc = 0; + for (int j = 0; j < p.length(); ++j) { + if (c[j] == '=') { + ++eqc; + + if (eqc > 1) { + break; + } + } + } + + if (eqc > 1 || eqc == 0) { + continue; + } + + String key = p.get_slicec('=', 0).replace("+", " ").percent_decode(); + String value = p.get_slicec('=', 1).replace("+", " ").percent_decode(); + + _request->add_parameter(key, value); + } +} + #define MESSAGE_DEBUG 0 int HTTPParser::on_message_begin() { @@ -405,8 +439,7 @@ int HTTPParser::on_message_complete() { //} else if (_content_type == REQUEST_CONTENT_URLENCODED) { - //Parse the content into the request - //Also add content body + process_urlenc_data(); } _requests.push_back(_request); diff --git a/modules/web/http_server_simple/http_parser.h b/modules/web/http_server_simple/http_parser.h index 8292005c0..a39ddf545 100644 --- a/modules/web/http_server_simple/http_parser.h +++ b/modules/web/http_server_simple/http_parser.h @@ -49,6 +49,7 @@ private: void process_multipart_data(); void _process_multipart_header(const String &header); + void process_urlenc_data(); int on_message_begin(); int on_url(const char *at, size_t length);