diff options
| author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 14:43:57 +0100 | 
|---|---|---|
| committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 14:43:57 +0100 | 
| commit | 31a118b91767e8951b14366d24a436f4cbffb7b1 (patch) | |
| tree | f843a7096d843b31dd5d200f87ae1982ab228a12 | |
| parent | b77ba4c739d25768dc56b47a929d800266c3230b (diff) | |
Parse query strings.
| -rw-r--r-- | http.cpp | 22 | ||||
| -rw-r--r-- | http.h | 5 | 
2 files changed, 24 insertions, 3 deletions
| @@ -7,7 +7,7 @@  #include <vector>  HTTPRequest::HTTPRequest(std::istream& is) { -	std::string firstline; +	std::string firstline, query_str;  	std::getline(is, firstline);  	std::vector<std::string> splitvec; @@ -15,8 +15,26 @@ HTTPRequest::HTTPRequest(std::istream& is) {  	type = splitvec[0];  	path = splitvec[1]; -	url_decode(path);  	httpver = splitvec[2]; + +	if(path.find("?") != std::string::npos) { +		boost::algorithm::split(splitvec, path, boost::is_any_of("?")); +		path = splitvec[0]; +		query_str = splitvec[1]; +		boost::algorithm::split(splitvec, query_str, boost::is_any_of("&")); +		for(std::vector<std::string>::iterator it = splitvec.begin(); it != splitvec.end(); it++) { +			std::vector<std::string> sv; +			boost::algorithm::split(sv, *it, boost::is_any_of("=")); +			std::string key = sv[0]; +			std::string value = sv[1]; +			url_decode(key); +			url_decode(value); +			query[key] = value; +			std::cout << boost::format("%s: %s") % key % value << std::endl; +		} +	} +	url_decode(path); +  	std::cout << boost::format("%s %s %s\n") % type % path % httpver;  	while(is.good()) { @@ -7,11 +7,14 @@  #include <string>  #include <map> -typedef std::map<std::string, std::string> HTTPHeaders; +typedef std::map<std::string, std::string> stringmap; +typedef stringmap HTTPHeaders; +typedef stringmap HTTPQuery;  class HTTPRequest {  	public:  		std::string type, path, httpver; +		HTTPQuery query;  		HTTPHeaders headers;  		HTTPRequest(std::istream& is);  		static void url_decode(std::string& str); | 
