diff --git a/lib/http_parser.cpp b/lib/http_parser.cpp index 165d5761..da8a51e6 100644 --- a/lib/http_parser.cpp +++ b/lib/http_parser.cpp @@ -447,7 +447,7 @@ bool HTTP::Parser::parse(std::string & HTTPbuffer) { tmpA.erase(0, f + 1); method = tmpA; if (url.find('?') != std::string::npos) { - parseVars(url.substr(url.find('?') + 1)); //parse GET variables + parseVars(url.substr(url.find('?') + 1), vars); //parse GET variables url.erase(url.find('?')); } url = Encodings::URL::decode(url); @@ -463,7 +463,7 @@ bool HTTP::Parser::parse(std::string & HTTPbuffer) { tmpA.erase(0, f + 1); protocol = tmpA; if (url.find('?') != std::string::npos) { - parseVars(url.substr(url.find('?') + 1)); //parse GET variables + parseVars(url.substr(url.find('?') + 1), vars); //parse GET variables url.erase(url.find('?')); } url = Encodings::URL::decode(url); @@ -508,7 +508,7 @@ bool HTTP::Parser::parse(std::string & HTTPbuffer) { HTTPbuffer.erase(0, toappend); } if (length == body.length()) { - parseVars(body); //parse POST variables + parseVars(body, vars); //parse POST variables return true; } else { return false; @@ -560,12 +560,12 @@ bool HTTP::Parser::parse(std::string & HTTPbuffer) { return false; //empty input } //HTTPReader::parse -/// Parses GET or POST-style variable data. -/// Saves to internal variable structure using HTTP::Parser::SetVar. -void HTTP::Parser::parseVars(std::string data) { +///HTTP variable parser to std::map structure. +///Reads variables from data, decodes and stores them to storage. +void HTTP::parseVars(const std::string & data, std::map & storage) { std::string varname; std::string varval; - // position where a part start (e.g. after &) + // position where a part starts (e.g. after &) size_t pos = 0; while (pos < data.length()) { size_t nextpos = data.find('&', pos); @@ -582,7 +582,9 @@ void HTTP::Parser::parseVars(std::string data) { varname = data.substr(pos, nextpos - pos); varval.clear(); } - SetVar(Encodings::URL::decode(varname), Encodings::URL::decode(varval)); + if (varname.size()){ + storage[Encodings::URL::decode(varname)] = Encodings::URL::decode(varval); + } if (nextpos == std::string::npos) { // in case the string is gigantic break; diff --git a/lib/http_parser.h b/lib/http_parser.h index 5a716af6..885772eb 100644 --- a/lib/http_parser.h +++ b/lib/http_parser.h @@ -10,6 +10,12 @@ /// Holds all HTTP processing related code. namespace HTTP { + + ///HTTP variable parser to std::map structure. + ///Reads variables from data, decodes and stores them to storage. + void parseVars(const std::string & data, std::map & storage); + + /// Simple class for reading and writing HTTP 1.0 and 1.1. class Parser { public: @@ -56,7 +62,6 @@ namespace HTTP { bool getChunks; unsigned int doingChunk; bool parse(std::string & HTTPbuffer); - void parseVars(std::string data); std::string builder; std::string read_buffer; std::map headers;