mirror of
https://github.com/boostorg/beast.git
synced 2026-08-03 20:14:17 +02:00
basic_parser ignores connection and framing fields in trailers
This commit is contained in:
committed by
Mohammad Nejati
parent
077efe520d
commit
60b4c2e3fc
@@ -387,15 +387,19 @@ inner_parse_fields(char const*& in,
|
||||
if(ec)
|
||||
return;
|
||||
auto const f = string_to_field(name);
|
||||
do_field(f, value, ec);
|
||||
if(ec)
|
||||
return;
|
||||
if(BOOST_UNLIKELY(state_ == state::trailer_fields))
|
||||
{
|
||||
// do_field() applies header-section semantics
|
||||
// (Content-Length, Transfer-Encoding, Connection,
|
||||
// Upgrade) which must not be honored when they appear
|
||||
// in a chunked trailer, see rfc7230 section 4.1.2.
|
||||
this->on_trailer_field_impl(f, name, value, ec);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_field(f, value, ec);
|
||||
if(ec)
|
||||
return;
|
||||
this->on_field_impl(f, name, value, ec);
|
||||
}
|
||||
if(ec)
|
||||
|
||||
@@ -404,6 +404,43 @@ public:
|
||||
// standard, not listed in Trailer
|
||||
BEAST_EXPECT(! p.get().contains(field::content_digest));
|
||||
}
|
||||
|
||||
// rfc7230 section 4.1.2: framing and connection control
|
||||
// fields carried in a trailer must not affect the message
|
||||
{
|
||||
error_code ec;
|
||||
parser_type<false> p;
|
||||
p.eager(true);
|
||||
p.put(
|
||||
buf("HTTP/1.1 200 OK\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"\r\n"
|
||||
"0\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n"),
|
||||
ec);
|
||||
BEAST_EXPECT(p.is_done());
|
||||
// Connection in the trailer must not close the connection
|
||||
BEAST_EXPECT(p.keep_alive());
|
||||
}
|
||||
{
|
||||
error_code ec;
|
||||
parser_type<true> p;
|
||||
p.eager(true);
|
||||
p.put(
|
||||
buf("GET / HTTP/1.1\r\n"
|
||||
"Host: localhost\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"\r\n"
|
||||
"0\r\n"
|
||||
"Connection: upgrade\r\n"
|
||||
"Upgrade: websocket\r\n"
|
||||
"\r\n"),
|
||||
ec);
|
||||
BEAST_EXPECT(p.is_done());
|
||||
// Upgrade in the trailer must not mark the message as upgrade
|
||||
BEAST_EXPECT(! p.upgrade());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user