summaryrefslogtreecommitdiff
path: root/http.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'http.cpp')
-rw-r--r--http.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/http.cpp b/http.cpp
index dbe8145..46f8e40 100644
--- a/http.cpp
+++ b/http.cpp
@@ -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;