decode all URIs, fixes #937, 386
This commit is contained in:
parent
0baa8215ef
commit
32bf99ba40
@ -45,7 +45,8 @@ RequestHandler::RequestHandler() : routing_machine(NULL) { }
|
|||||||
void RequestHandler::handle_request(const http::Request& req, http::Reply& rep){
|
void RequestHandler::handle_request(const http::Request& req, http::Reply& rep){
|
||||||
//parse command
|
//parse command
|
||||||
try {
|
try {
|
||||||
std::string request(req.uri);
|
std::string request;
|
||||||
|
URIDecode(req.uri, request);
|
||||||
|
|
||||||
time_t ltime;
|
time_t ltime;
|
||||||
struct tm *Tm;
|
struct tm *Tm;
|
||||||
@ -61,7 +62,7 @@ void RequestHandler::handle_request(const http::Request& req, http::Reply& rep){
|
|||||||
Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) <<
|
Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) <<
|
||||||
Tm->tm_sec << " " << req.endpoint.to_string() << " " <<
|
Tm->tm_sec << " " << req.endpoint.to_string() << " " <<
|
||||||
req.referrer << ( 0 == req.referrer.length() ? "- " :" ") <<
|
req.referrer << ( 0 == req.referrer.length() ? "- " :" ") <<
|
||||||
req.agent << ( 0 == req.agent.length() ? "- " :" ") << req.uri;
|
req.agent << ( 0 == req.agent.length() ? "- " :" ") << request;
|
||||||
|
|
||||||
RouteParameters route_parameters;
|
RouteParameters route_parameters;
|
||||||
APIGrammarParser api_parser(&route_parameters);
|
APIGrammarParser api_parser(&route_parameters);
|
||||||
|
@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <boost/spirit/include/qi.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cctype>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// precision: position after decimal point
|
// precision: position after decimal point
|
||||||
@ -177,6 +178,36 @@ inline std::string HTMLDeEntitize( std::string & result) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::size_t URIDecode(const std::string & input, std::string & output) {
|
||||||
|
std::string::const_iterator src_iter = input.begin();
|
||||||
|
output.resize(input.size()+1);
|
||||||
|
std::size_t decoded_length = 0;
|
||||||
|
for( decoded_length = 0; src_iter != input.end(); ++decoded_length ) {
|
||||||
|
if(
|
||||||
|
src_iter[0] == '%' &&
|
||||||
|
src_iter[1] &&
|
||||||
|
src_iter[2] &&
|
||||||
|
isxdigit(src_iter[1]) &&
|
||||||
|
isxdigit(src_iter[2])
|
||||||
|
) {
|
||||||
|
std::string::value_type a = src_iter[1];
|
||||||
|
std::string::value_type b = src_iter[2];
|
||||||
|
a -= src_iter[1] < 58 ? 48 : src_iter[1] < 71 ? 55 : 87;
|
||||||
|
b -= src_iter[2] < 58 ? 48 : src_iter[2] < 71 ? 55 : 87;
|
||||||
|
output[decoded_length] = 16 * a + b;
|
||||||
|
src_iter += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
output[decoded_length] = *src_iter++;
|
||||||
|
}
|
||||||
|
output.resize(decoded_length);
|
||||||
|
return decoded_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t URIDecodeInPlace(std::string & URI) {
|
||||||
|
return URIDecode(URI, URI);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool StringStartsWith(
|
inline bool StringStartsWith(
|
||||||
const std::string & input,
|
const std::string & input,
|
||||||
const std::string & prefix
|
const std::string & prefix
|
||||||
|
Loading…
Reference in New Issue
Block a user