Check trailers in test

This commit is contained in:
Vinnie Falco
2017-07-02 06:38:10 -07:00
parent 2878b38b64
commit f3afc834b1
3 changed files with 12 additions and 4 deletions

View File

@ -4,6 +4,7 @@ Version 71:
* Documentation revision * Documentation revision
* Fix spurious on_chunk invocation * Fix spurious on_chunk invocation
* Call prepare_payload in HTTP example * Call prepare_payload in HTTP example
* Check trailers in test
WebSockets: WebSockets:

View File

@ -1099,7 +1099,7 @@ public:
bufgrind<test_parser<false>>( bufgrind<test_parser<false>>(
"HTTP/1.1 200 OK\r\n" "HTTP/1.1 200 OK\r\n"
"Server: test\r\n" "Server: test\r\n"
"Expect: Expires, MD5-Fingerprint\r\n" "Trailer: Expires, MD5-Fingerprint\r\n"
"Transfer-Encoding: chunked\r\n" "Transfer-Encoding: chunked\r\n"
"\r\n" "\r\n"
"5\r\n" "5\r\n"
@ -1110,9 +1110,11 @@ public:
"Expires: never\r\n" "Expires: never\r\n"
"MD5-Fingerprint: -\r\n" "MD5-Fingerprint: -\r\n"
"\r\n" "\r\n"
,[&](test_parser<false> const& p) ,[&](test_parser<false>& p)
{ {
BEAST_EXPECT(p.body == "*****--"); BEAST_EXPECT(p.body == "*****--");
BEAST_EXPECT(p.fields["Expires"] == "never");
BEAST_EXPECT(p.fields["MD5-Fingerprint"] == "-");
}); });
} }

View File

@ -10,6 +10,8 @@
#include <beast/http/basic_parser.hpp> #include <beast/http/basic_parser.hpp>
#include <beast/test/fail_counter.hpp> #include <beast/test/fail_counter.hpp>
#include <string>
#include <unordered_map>
namespace beast { namespace beast {
namespace http { namespace http {
@ -37,6 +39,8 @@ public:
bool got_content_length = false; bool got_content_length = false;
bool got_on_chunk = false; bool got_on_chunk = false;
bool got_on_complete = false; bool got_on_complete = false;
std::unordered_map<
std::string, std::string> fields;
test_parser() = default; test_parser() = default;
@ -79,14 +83,15 @@ public:
} }
void void
on_field(field, string_view, on_field(field, string_view name,
string_view, error_code& ec) string_view value, error_code& ec)
{ {
got_on_field = true; got_on_field = true;
if(fc_) if(fc_)
fc_->fail(ec); fc_->fail(ec);
else else
ec.assign(0, ec.category()); ec.assign(0, ec.category());
fields[name.to_string()] = value.to_string();
} }
void void