aboutsummaryrefslogtreecommitdiffstats
path: root/parser.h
diff options
context:
space:
mode:
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_;
+ };
+}