summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-01-02 21:41:56 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-01-02 21:45:46 +0100
commitb53ea34b123721f70ae6e4ff4eb96e90e0664ba4 (patch)
treea7e510d77313e288a1ed3c71acbc7b0a40bc0153
parent226fd63fab4b5b605c62049c6a9d765de8d6c4db (diff)
Move HTTP::Connection::parse_request into new file.
-rw-r--r--http_connection.cpp35
-rw-r--r--http_connection_parser.cpp37
2 files changed, 37 insertions, 35 deletions
diff --git a/http_connection.cpp b/http_connection.cpp
index d940b2f..6567f81 100644
--- a/http_connection.cpp
+++ b/http_connection.cpp
@@ -3,10 +3,6 @@
#include "http.h"
#include <boost/bind.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/fusion/include/std_pair.hpp>
-
-namespace qi = boost::spirit::qi;
HTTP::Connection::Connection(boost::asio::io_service& io_service) : socket(io_service) {
}
@@ -43,37 +39,6 @@ void print(char c) {
std::cout << "Char: " << int(c) << std::endl;
}
-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<Iterator, std::string()> word_p = +(qi::char_ - ' ' - '\r');
-
- qi::rule<Iterator, char()> urlchar_p = (qi::char_ - '%') | ('%' >> qi::uint_parser<char, 16, 2, 2>());
-
- qi::rule<Iterator, PathList()> path_p = *(+qi::lit('/') >> +(urlchar_p - '/' - '?' - ' ')) >> *qi::lit('/');
-
- qi::rule<Iterator, std::pair<std::string, std::string>()> pair_p = +(urlchar_p - '=') >> '=' >> +(urlchar_p - '&' - ' ');
- qi::rule<Iterator, std::map<std::string, std::string>()> args_p = '?' >> pair_p >> *('&' >> pair_p);
-
- qi::rule<Iterator, std::pair<std::string, std::string>()> header_p = +(qi::char_ - ':') >> ": " >> +(qi::char_ - '\r');
- qi::rule<Iterator, std::map<std::string, std::string>()> 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);
-}
-
void HTTP::Connection::read_request(Handler callback) {
boost::asio::async_read_until(socket, buf, "\r\n\r\n", boost::bind(&Connection::handle_read, shared_from_this(),
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, callback));
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 <boost/spirit/include/qi.hpp>
+#include <boost/fusion/include/std_pair.hpp>
+
+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<Iterator, std::string()> word_p = +(qi::char_ - ' ' - '\r');
+
+ qi::rule<Iterator, char()> urlchar_p = (qi::char_ - '%') | ('%' >> qi::uint_parser<char, 16, 2, 2>());
+
+ qi::rule<Iterator, PathList()> path_p = *(+qi::lit('/') >> +(urlchar_p - '/' - '?' - ' ')) >> *qi::lit('/');
+
+ qi::rule<Iterator, std::pair<std::string, std::string>()> pair_p = +(urlchar_p - '=') >> '=' >> +(urlchar_p - '&' - ' ');
+ qi::rule<Iterator, std::map<std::string, std::string>()> args_p = '?' >> pair_p >> *('&' >> pair_p);
+
+ qi::rule<Iterator, std::pair<std::string, std::string>()> header_p = +(qi::char_ - ':') >> ": " >> +(qi::char_ - '\r');
+ qi::rule<Iterator, std::map<std::string, std::string>()> 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);
+}