diff options
Diffstat (limited to 'include/parser.h')
-rw-r--r-- | include/parser.h | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/include/parser.h b/include/parser.h index f504248..1b8240f 100644 --- a/include/parser.h +++ b/include/parser.h @@ -82,7 +82,15 @@ namespace crow return 0; } HTTPParser(Handler* handler) : - settings_ { + handler_(handler) + { + http_parser_init(this, HTTP_REQUEST); + } + + // return false on error + bool feed(const char* buffer, int length) + { + const static http_parser_settings settings_{ on_message_begin, on_url, nullptr, @@ -91,23 +99,15 @@ namespace crow on_headers_complete, on_body, on_message_complete, - }, - handler_(handler) - { - http_parser_init(this, HTTP_REQUEST); - } + }; - // return false on error - bool feed(const char* buffer, int length) - { int nparsed = http_parser_execute(this, &settings_, buffer, length); return nparsed == length; } bool done() { - int nparsed = http_parser_execute(this, &settings_, nullptr, 0); - return nparsed == 0; + return feed(nullptr, 0); } void clear() @@ -147,8 +147,6 @@ namespace crow std::unordered_map<std::string, std::string> headers; std::string body; - http_parser_settings settings_; - Handler* handler_; }; } |