aboutsummaryrefslogtreecommitdiffstats
path: root/include/parser.h
diff options
context:
space:
mode:
authoripkn <ipknhama@gmail.com>2014-10-23 23:44:31 +0900
committeripkn <ipknhama@gmail.com>2014-10-23 23:44:31 +0900
commit4965d495a7ada4fb7c6aeed1fd6c4b5830bb99a9 (patch)
treea65f112b1df3035807c3b5dfab9aca86d86d1d1e /include/parser.h
parenta5fab23f70e6e33c633ba4b646a41d0851169ad1 (diff)
parentada303970732f00e2d3017b726effad65d27a4d2 (diff)
downloadcrow-4965d495a7ada4fb7c6aeed1fd6c4b5830bb99a9.tar.gz
crow-4965d495a7ada4fb7c6aeed1fd6c4b5830bb99a9.zip
Merge pull request #28 from acron0/url-params-in-req
Added URL params (request.url_params)
Diffstat (limited to 'include/parser.h')
-rw-r--r--include/parser.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/include/parser.h b/include/parser.h
index 869061c..6ead8fd 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -3,6 +3,8 @@
#include <string>
#include <unordered_map>
#include <boost/algorithm/string.hpp>
+#include <boost/tokenizer.hpp>
+#include <algorithm>
#include "http_request.h"
@@ -20,7 +22,7 @@ namespace crow
static int on_url(http_parser* self_, const char* at, size_t length)
{
HTTPParser* self = static_cast<HTTPParser*>(self_);
- self->url.insert(self->url.end(), at, at+length);
+ self->raw_url.insert(self->raw_url.end(), at, at+length);
return 0;
}
static int on_header_field(http_parser* self_, const char* at, size_t length)
@@ -76,6 +78,11 @@ namespace crow
static int on_message_complete(http_parser* self_)
{
HTTPParser* self = static_cast<HTTPParser*>(self_);
+
+ // url params
+ self->url = self->raw_url.substr(0, self->raw_url.find("?"));
+ self->url_params = query_string(self->raw_url);
+
self->process_message();
return 0;
}
@@ -111,10 +118,12 @@ namespace crow
void clear()
{
url.clear();
+ raw_url.clear();
header_building_state = 0;
header_field.clear();
header_value.clear();
headers.clear();
+ url_params.clear();
body.clear();
}
@@ -130,7 +139,7 @@ namespace crow
request to_request() const
{
- return request{(HTTPMethod)method, std::move(url), std::move(headers), std::move(body)};
+ return request{(HTTPMethod)method, std::move(raw_url), std::move(url), std::move(url_params), std::move(headers), std::move(body)};
}
bool check_version(int major, int minor) const
@@ -138,11 +147,14 @@ namespace crow
return http_major == major && http_minor == minor;
}
+ std::string raw_url;
std::string url;
+
int header_building_state = 0;
std::string header_field;
std::string header_value;
ci_map headers;
+ query_string url_params;
std::string body;
Handler* handler_;