diff options
author | Antony Woods <acron1@gmail.com> | 2014-10-24 09:40:09 +0100 |
---|---|---|
committer | Antony Woods <acron1@gmail.com> | 2014-10-24 09:40:09 +0100 |
commit | 693aac108de4dc62811b9a2737d895ada474cfb2 (patch) | |
tree | 44cc722afea8b6ef26095cd27aa64b97ec48d74e /include/parser.h | |
parent | 27bf11d35c8ce44fd9fef656e2975712846b9bb2 (diff) | |
parent | 4b3b8070e75ce0fc181e5c012c47da2a1e7a918e (diff) | |
download | crow-693aac108de4dc62811b9a2737d895ada474cfb2.tar.gz crow-693aac108de4dc62811b9a2737d895ada474cfb2.zip |
Post-pull commit
Diffstat (limited to 'include/parser.h')
-rw-r--r-- | include/parser.h | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/include/parser.h b/include/parser.h index 869061c..f6b748b 100644 --- a/include/parser.h +++ b/include/parser.h @@ -3,7 +3,10 @@ #include <string> #include <unordered_map> #include <boost/algorithm/string.hpp> +#include <boost/tokenizer.hpp> +#include <algorithm> +#include "http_parser_merged.h" #include "http_request.h" namespace crow @@ -20,7 +23,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 +79,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 +119,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 +140,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 +148,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_; |