diff --git a/CHANGELOG.md b/CHANGELOG.md index ac9e3bfe..ea4e0b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fix message_v1 constructor * Tidy up DynamicBuffer requirements * Tidy up error types and headers +* Fix handling empty HTTP headers in parser_v1 -------------------------------------------------------------------------------- diff --git a/include/beast/http/parser_v1.hpp b/include/beast/http/parser_v1.hpp index aada5243..643c4d37 100644 --- a/include/beast/http/parser_v1.hpp +++ b/include/beast/http/parser_v1.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,7 @@ private: message_type m_; typename message_type::body_type::reader r_; std::uint8_t skip_body_ = 0; + bool flush_ = false; public: parser_v1(parser_v1&&) = default; @@ -161,12 +163,13 @@ private: void flush() { - if(! value_.empty()) - { - m_.headers.insert(field_, value_); - field_.clear(); - value_.clear(); - } + if(! flush_) + return; + flush_ = false; + BOOST_ASSERT(! field_.empty()); + m_.headers.insert(field_, value_); + field_.clear(); + value_.clear(); } void on_start(error_code&) @@ -197,6 +200,7 @@ private: void on_value(boost::string_ref const& s, error_code&) { value_.append(s.data(), s.size()); + flush_ = true; } void set(std::true_type) diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index 618e54f0..76aaecc4 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -263,7 +263,7 @@ public: } catch(system_error const& se) { - BEAST_EXPECT(se.code() == ev); + BEAST_EXPECTS(se.code() == ev, se.what()); } } };