summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--http.cpp24
-rw-r--r--http.h1
2 files changed, 25 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;
diff --git a/http.h b/http.h
index 3ab66dc..ef6e43c 100644
--- a/http.h
+++ b/http.h
@@ -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 {