Clear previous message fields in parser

fix #818
This commit is contained in:
Vinnie Falco
2017-10-16 12:09:20 -07:00
parent e832baf93f
commit 2399b610e3
4 changed files with 22 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ Version 123:
* Use unit-test subtree
* Fix spurious race in websocket close test
* Check compiler feature in Jamfile
* Clear previous message fields in parser
--------------------------------------------------------------------------------

View File

@@ -373,17 +373,19 @@ public:
//
//--------------------------------------------------------------------------
private:
// VFALCO But this leaves behind the method, target, and reason!
/** Remove all fields from the container
All references, pointers, or iterators referring to contained
elements are invalidated. All past-the-end iterators are also
invalidated.
@par Postconditions:
@code
std::distance(this->begin(), this->end()) == 0
@encode
*/
void
clear();
public:
/** Insert a field.

View File

@@ -32,6 +32,7 @@ parser(Arg1&& arg1, ArgN&&... argn)
std::forward<ArgN>(argn)...)
, wr_(m_)
{
m_.clear();
}
template<bool isRequest, class Body, class Allocator>

View File

@@ -21,6 +21,7 @@
#include <boost/beast/http/read.hpp>
#include <boost/beast/http/string_body.hpp>
#include <boost/system/system_error.hpp>
#include <algorithm>
namespace boost {
namespace beast {
@@ -329,6 +330,19 @@ public:
BEAST_EXPECT(used == 0);
}
void
testIssue818()
{
// Make sure that the parser clears pre-existing fields
request<string_body> m;
m.set(field::accept, "html/text");
BEAST_EXPECT(std::distance(m.begin(), m.end()) == 1);
request_parser<string_body> p{std::move(m)};
BEAST_EXPECT(std::distance(m.begin(), m.end()) == 0);
auto& m1 = p.get();
BEAST_EXPECT(std::distance(m1.begin(), m1.end()) == 0);
}
void
run() override
{
@@ -336,6 +350,7 @@ public:
testNeedMore<flat_buffer>();
testNeedMore<multi_buffer>();
testGotSome();
testIssue818();
}
};