aboutsummaryrefslogtreecommitdiffstats
path: root/parser.h
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-04-01 01:51:50 +0900
committeripknHama <ipknhama@gmail.com>2014-04-01 01:51:50 +0900
commit4b8c67e2300205200f4f846400d73a03cb3da854 (patch)
tree46b63650efd6952cf88a62cc0511162af54d896f /parser.h
parent1e11a177ee6b680b55f01d6090ccd1b2e2b8c51c (diff)
downloadcrow-4b8c67e2300205200f4f846400d73a03cb3da854.tar.gz
crow-4b8c67e2300205200f4f846400d73a03cb3da854.zip
accept connections, print http request parsed information
Diffstat (limited to 'parser.h')
-rw-r--r--parser.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/parser.h b/parser.h
new file mode 100644
index 0000000..2f2626d
--- /dev/null
+++ b/parser.h
@@ -0,0 +1,79 @@
+#include <iostream>
+#include <string>
+namespace flask
+{
+ struct HTTPParser : public http_parser
+ {
+ static int on_message_begin(http_parser* self_)
+ {
+ HTTPParser* self = static_cast<HTTPParser*>(self_);
+ return 0;
+ }
+ static int on_url(http_parser* self_, const char* at, size_t length)
+ {
+ HTTPParser* self = static_cast<HTTPParser*>(self_);
+ std::cout << std::string(at, at+length) << std::endl;
+ return 0;
+ }
+ static int on_status(http_parser* self_, const char* at, size_t length)
+ {
+ HTTPParser* self = static_cast<HTTPParser*>(self_);
+ std::cout << std::string(at, at+length) << std::endl;
+ return 0;
+ }
+ static int on_header_field(http_parser* self_, const char* at, size_t length)
+ {
+ HTTPParser* self = static_cast<HTTPParser*>(self_);
+ std::cout << std::string(at, at+length) << std::endl;
+ return 0;
+ }
+ static int on_header_value(http_parser* self_, const char* at, size_t length)
+ {
+ HTTPParser* self = static_cast<HTTPParser*>(self_);
+ std::cout << std::string(at, at+length) << std::endl;
+ return 0;
+ }
+ static int on_headers_complete(http_parser* self_)
+ {
+ HTTPParser* self = static_cast<HTTPParser*>(self_);
+ return 0;
+ }
+ static int on_body(http_parser* self_, const char* at, size_t length)
+ {
+ HTTPParser* self = static_cast<HTTPParser*>(self_);
+ std::cout << std::string(at, at+length) << std::endl;
+ return 0;
+ }
+ static int on_message_complete(http_parser* self_)
+ {
+ HTTPParser* self = static_cast<HTTPParser*>(self_);
+ return 0;
+ }
+ HTTPParser() :
+ settings_ {
+ on_message_begin,
+ on_url,
+ on_status,
+ on_header_field,
+ on_header_value,
+ on_headers_complete,
+ on_body,
+ on_message_complete,
+ }
+ {
+ http_parser_init(this, HTTP_REQUEST);
+ }
+
+ void feed(const char* buffer, int length)
+ {
+ int nparsed = http_parser_execute(this, &settings_, buffer, length);
+ }
+
+ void done()
+ {
+ int nparsed = http_parser_execute(this, &settings_, nullptr, 0);
+ }
+
+ http_parser_settings settings_;
+ };
+}