From b53ea34b123721f70ae6e4ff4eb96e90e0664ba4 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 2 Jan 2011 21:41:56 +0100 Subject: Move HTTP::Connection::parse_request into new file. --- http_connection_parser.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 http_connection_parser.cpp (limited to 'http_connection_parser.cpp') diff --git a/http_connection_parser.cpp b/http_connection_parser.cpp new file mode 100644 index 0000000..fc1b948 --- /dev/null +++ b/http_connection_parser.cpp @@ -0,0 +1,37 @@ +#include "http_connection.h" + +#include +#include + +namespace qi = boost::spirit::qi; + +bool HTTP::Connection::parse_request(boost::asio::streambuf& buf) { + std::string data(boost::asio::buffers_begin(buf.data()), boost::asio::buffers_end(buf.data())); + + typedef std::string::const_iterator Iterator; + + Iterator begin = data.begin(); + Iterator end = data.end(); + + qi::rule word_p = +(qi::char_ - ' ' - '\r'); + + qi::rule urlchar_p = (qi::char_ - '%') | ('%' >> qi::uint_parser()); + + qi::rule path_p = *(+qi::lit('/') >> +(urlchar_p - '/' - '?' - ' ')) >> *qi::lit('/'); + + qi::rule()> pair_p = +(urlchar_p - '=') >> '=' >> +(urlchar_p - '&' - ' '); + qi::rule()> args_p = '?' >> pair_p >> *('&' >> pair_p); + + qi::rule()> header_p = +(qi::char_ - ':') >> ": " >> +(qi::char_ - '\r'); + qi::rule()> headers_p = *(header_p >> "\r\n"); + + return qi::parse(begin, end, + // Method, path, args, version: + word_p >> ' ' >> path_p >> -args_p >> ' ' >> word_p >> "\r\n" >> + // Headers: + headers_p >> + // End of headers: + "\r\n", + // Store into: + method, path, args, version, headers); +} -- cgit v1.2.3