diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 04:08:35 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 04:08:35 +0100 |
commit | b77ba4c739d25768dc56b47a929d800266c3230b (patch) | |
tree | f3bdb5d479eb800ce0b931721846116f37a90849 | |
parent | 6b7c665baaf6023ee1cd935a953711fe65fff73b (diff) |
Added a shady url decoder for paths.
-rw-r--r-- | http.cpp | 24 | ||||
-rw-r--r-- | http.h | 1 |
2 files changed, 25 insertions, 0 deletions
@@ -15,6 +15,7 @@ HTTPRequest::HTTPRequest(std::istream& is) { type = splitvec[0]; path = splitvec[1]; + url_decode(path); httpver = splitvec[2]; std::cout << boost::format("%s %s %s\n") % type % path % httpver; @@ -29,6 +30,29 @@ HTTPRequest::HTTPRequest(std::istream& is) { } } +void HTTPRequest::url_decode(std::string& str) { + std::string::const_iterator start, end, prev; + start = str.begin(); + end = str.end(); + boost::match_results<std::string::const_iterator> what; + boost::match_flag_type flags = boost::match_default; + boost::regex re("%([0-9a-fA-F]{2})"); + prev = start; + std::string out; + while(boost::regex_search(start, end, what, re, flags)) { + std::istringstream hs(what[1]); + char c; + int hi; + hs >> std::hex >> hi; + c = hi; + out += std::string(prev, what[1].first - 1) + c; + start = what[1].second; + prev = start; + } + out += std::string(prev, end); + str = out; +} + HTTPResponse::HTTPResponse(boost::asio::ip::tcp::socket& socket_) : socket(socket_){ httpver = "1.1"; headers_written = false; @@ -14,6 +14,7 @@ class HTTPRequest { std::string type, path, httpver; HTTPHeaders headers; HTTPRequest(std::istream& is); + static void url_decode(std::string& str); }; class HTTPResponse { |