2016-11-20 07:32:41 -05:00
|
|
|
//
|
2019-02-21 07:00:31 -08:00
|
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2016-11-20 07:32:41 -05:00
|
|
|
//
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
//
|
2017-07-20 13:40:34 -07:00
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
|
//
|
2016-11-20 07:32:41 -05:00
|
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/http/parser.hpp>
|
2016-11-20 07:32:41 -05:00
|
|
|
|
|
|
|
|
#include "test_parser.hpp"
|
|
|
|
|
|
2018-11-11 14:07:55 -08:00
|
|
|
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
2019-03-05 08:25:54 -08:00
|
|
|
#include <boost/beast/core/buffer_traits.hpp>
|
2017-09-15 12:52:45 -07:00
|
|
|
#include <boost/beast/core/buffers_suffix.hpp>
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/core/flat_buffer.hpp>
|
|
|
|
|
#include <boost/beast/core/multi_buffer.hpp>
|
|
|
|
|
#include <boost/beast/core/ostream.hpp>
|
|
|
|
|
#include <boost/beast/http/string_body.hpp>
|
2016-11-20 07:32:41 -05:00
|
|
|
#include <boost/system/system_error.hpp>
|
2017-10-16 12:09:20 -07:00
|
|
|
#include <algorithm>
|
2016-11-20 07:32:41 -05:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2016-11-20 07:32:41 -05:00
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
2017-06-03 08:40:53 -07:00
|
|
|
class parser_test
|
2016-11-20 07:32:41 -05:00
|
|
|
: public beast::unit_test::suite
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-05-31 08:01:55 -07:00
|
|
|
template<bool isRequest>
|
|
|
|
|
using parser_type =
|
2017-06-19 11:54:53 -07:00
|
|
|
parser<isRequest, string_body>;
|
2017-05-31 08:01:55 -07:00
|
|
|
|
|
|
|
|
static
|
2018-11-30 14:58:38 -08:00
|
|
|
net::const_buffer
|
2017-05-31 08:01:55 -07:00
|
|
|
buf(string_view s)
|
|
|
|
|
{
|
|
|
|
|
return {s.data(), s.size()};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class ConstBufferSequence,
|
2019-02-23 06:55:12 -08:00
|
|
|
bool isRequest>
|
2017-05-31 08:01:55 -07:00
|
|
|
static
|
2016-11-20 07:32:41 -05:00
|
|
|
void
|
2017-05-31 08:01:55 -07:00
|
|
|
put(ConstBufferSequence const& buffers,
|
2019-02-23 06:55:12 -08:00
|
|
|
basic_parser<isRequest>& p,
|
2017-05-31 08:01:55 -07:00
|
|
|
error_code& ec)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
2017-09-15 12:52:45 -07:00
|
|
|
buffers_suffix<ConstBufferSequence> cb{buffers};
|
2017-05-31 08:01:55 -07:00
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
auto const used = p.put(cb, ec);
|
|
|
|
|
cb.consume(used);
|
|
|
|
|
if(ec)
|
|
|
|
|
return;
|
|
|
|
|
if(p.need_eof() &&
|
2019-03-05 08:47:02 -08:00
|
|
|
buffer_bytes(cb) == 0)
|
2017-05-31 08:01:55 -07:00
|
|
|
{
|
|
|
|
|
p.put_eof(ec);
|
|
|
|
|
if(ec)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(p.is_done())
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
template<bool isRequest, class F>
|
2016-11-20 07:32:41 -05:00
|
|
|
void
|
2017-05-31 08:01:55 -07:00
|
|
|
doMatrix(string_view s0, F const& f)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
2017-05-31 08:01:55 -07:00
|
|
|
// parse a single buffer
|
|
|
|
|
{
|
|
|
|
|
auto s = s0;
|
|
|
|
|
error_code ec;
|
|
|
|
|
parser_type<isRequest> p;
|
2019-02-02 20:44:04 -08:00
|
|
|
put(net::buffer(s.data(), s.size()), p, ec);
|
2017-07-25 12:35:54 -07:00
|
|
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
2017-05-31 08:01:55 -07:00
|
|
|
return;
|
|
|
|
|
f(p);
|
|
|
|
|
}
|
|
|
|
|
// parse two buffers
|
|
|
|
|
for(auto n = s0.size() - 1; n >= 1; --n)
|
|
|
|
|
{
|
|
|
|
|
auto s = s0;
|
|
|
|
|
error_code ec;
|
|
|
|
|
parser_type<isRequest> p;
|
|
|
|
|
p.eager(true);
|
|
|
|
|
auto used =
|
2019-02-02 20:44:04 -08:00
|
|
|
p.put(net::buffer(s.data(), n), ec);
|
2017-05-31 08:01:55 -07:00
|
|
|
s.remove_prefix(used);
|
|
|
|
|
if(ec == error::need_more)
|
2019-01-20 09:50:43 -08:00
|
|
|
ec = {};
|
2017-07-25 12:35:54 -07:00
|
|
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
2017-05-31 08:01:55 -07:00
|
|
|
continue;
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(! p.is_done());
|
2017-05-31 08:01:55 -07:00
|
|
|
used = p.put(
|
2019-02-02 20:44:04 -08:00
|
|
|
net::buffer(s.data(), s.size()), ec);
|
2017-05-31 08:01:55 -07:00
|
|
|
s.remove_prefix(used);
|
2017-07-25 12:35:54 -07:00
|
|
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
2017-05-31 08:01:55 -07:00
|
|
|
continue;
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(s.empty());
|
2017-05-31 08:01:55 -07:00
|
|
|
if(p.need_eof())
|
|
|
|
|
{
|
|
|
|
|
p.put_eof(ec);
|
2017-07-25 12:35:54 -07:00
|
|
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
2017-05-31 08:01:55 -07:00
|
|
|
continue;
|
|
|
|
|
}
|
2017-07-25 12:35:54 -07:00
|
|
|
if(BEAST_EXPECT(p.is_done()))
|
2017-05-31 08:01:55 -07:00
|
|
|
f(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
testParse()
|
|
|
|
|
{
|
|
|
|
|
doMatrix<false>(
|
2016-11-20 07:32:41 -05:00
|
|
|
"HTTP/1.0 200 OK\r\n"
|
|
|
|
|
"Server: test\r\n"
|
|
|
|
|
"\r\n"
|
2017-05-31 08:01:55 -07:00
|
|
|
"Hello, world!",
|
|
|
|
|
[&](parser_type<false> const& p)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
2017-05-31 08:01:55 -07:00
|
|
|
auto const& m = p.get();
|
2017-10-25 18:04:54 -07:00
|
|
|
BEAST_EXPECT(! p.chunked());
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(p.need_eof());
|
|
|
|
|
BEAST_EXPECT(p.content_length() == boost::none);
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(m.version() == 10);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m.result() == status::ok);
|
|
|
|
|
BEAST_EXPECT(m.reason() == "OK");
|
|
|
|
|
BEAST_EXPECT(m["Server"] == "test");
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(m.body() == "Hello, world!");
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
);
|
2017-05-31 08:01:55 -07:00
|
|
|
doMatrix<false>(
|
|
|
|
|
"HTTP/1.1 200 OK\r\n"
|
2016-11-20 07:32:41 -05:00
|
|
|
"Server: test\r\n"
|
2017-05-31 08:01:55 -07:00
|
|
|
"Expect: Expires, MD5-Fingerprint\r\n"
|
2016-11-20 07:32:41 -05:00
|
|
|
"Transfer-Encoding: chunked\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
"5\r\n"
|
|
|
|
|
"*****\r\n"
|
|
|
|
|
"2;a;b=1;c=\"2\"\r\n"
|
|
|
|
|
"--\r\n"
|
|
|
|
|
"0;d;e=3;f=\"4\"\r\n"
|
|
|
|
|
"Expires: never\r\n"
|
|
|
|
|
"MD5-Fingerprint: -\r\n"
|
|
|
|
|
"\r\n",
|
2017-05-31 08:01:55 -07:00
|
|
|
[&](parser_type<false> const& p)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
2017-05-31 08:01:55 -07:00
|
|
|
auto const& m = p.get();
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(! p.need_eof());
|
2017-10-25 18:04:54 -07:00
|
|
|
BEAST_EXPECT(p.chunked());
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(p.content_length() == boost::none);
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(m.version() == 11);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m.result() == status::ok);
|
|
|
|
|
BEAST_EXPECT(m.reason() == "OK");
|
|
|
|
|
BEAST_EXPECT(m["Server"] == "test");
|
|
|
|
|
BEAST_EXPECT(m["Transfer-Encoding"] == "chunked");
|
|
|
|
|
BEAST_EXPECT(m["Expires"] == "never");
|
|
|
|
|
BEAST_EXPECT(m["MD5-Fingerprint"] == "-");
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(m.body() == "*****--");
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
);
|
2017-05-31 08:01:55 -07:00
|
|
|
doMatrix<false>(
|
2016-11-20 07:32:41 -05:00
|
|
|
"HTTP/1.0 200 OK\r\n"
|
|
|
|
|
"Server: test\r\n"
|
|
|
|
|
"Content-Length: 5\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
"*****",
|
2017-05-31 08:01:55 -07:00
|
|
|
[&](parser_type<false> const& p)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
2017-05-31 08:01:55 -07:00
|
|
|
auto const& m = p.get();
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(m.body() == "*****");
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
);
|
2017-05-31 08:01:55 -07:00
|
|
|
doMatrix<true>(
|
2016-11-20 07:32:41 -05:00
|
|
|
"GET / HTTP/1.1\r\n"
|
|
|
|
|
"User-Agent: test\r\n"
|
|
|
|
|
"\r\n",
|
2017-05-31 08:01:55 -07:00
|
|
|
[&](parser_type<true> const& p)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
2017-05-31 08:01:55 -07:00
|
|
|
auto const& m = p.get();
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m.method() == verb::get);
|
|
|
|
|
BEAST_EXPECT(m.target() == "/");
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(m.version() == 11);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(! p.need_eof());
|
2017-10-25 18:04:54 -07:00
|
|
|
BEAST_EXPECT(! p.chunked());
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(p.content_length() == boost::none);
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
);
|
2017-05-31 08:01:55 -07:00
|
|
|
doMatrix<true>(
|
2016-11-20 07:32:41 -05:00
|
|
|
"GET / HTTP/1.1\r\n"
|
|
|
|
|
"User-Agent: test\r\n"
|
|
|
|
|
"X: \t x \t \r\n"
|
|
|
|
|
"\r\n",
|
2017-05-31 08:01:55 -07:00
|
|
|
[&](parser_type<true> const& p)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
2017-05-31 08:01:55 -07:00
|
|
|
auto const& m = p.get();
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m["X"] == "x");
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
// test eager(true)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
|
|
|
|
error_code ec;
|
2017-05-31 08:01:55 -07:00
|
|
|
parser_type<true> p;
|
|
|
|
|
p.eager(true);
|
|
|
|
|
p.put(buf(
|
2016-11-20 07:32:41 -05:00
|
|
|
"GET / HTTP/1.1\r\n"
|
|
|
|
|
"User-Agent: test\r\n"
|
|
|
|
|
"Content-Length: 1\r\n"
|
|
|
|
|
"\r\n"
|
2017-05-31 08:01:55 -07:00
|
|
|
"*")
|
|
|
|
|
, ec);
|
2016-11-20 07:32:41 -05:00
|
|
|
auto const& m = p.get();
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(! ec);
|
|
|
|
|
BEAST_EXPECT(p.is_done());
|
|
|
|
|
BEAST_EXPECT(p.is_header_done());
|
|
|
|
|
BEAST_EXPECT(! p.need_eof());
|
|
|
|
|
BEAST_EXPECT(m.method() == verb::get);
|
|
|
|
|
BEAST_EXPECT(m.target() == "/");
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(m.version() == 11);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m["User-Agent"] == "test");
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(m.body() == "*");
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
// test partial parsing of final chunk
|
|
|
|
|
// parse through the chunk body
|
2017-05-31 08:01:55 -07:00
|
|
|
error_code ec;
|
|
|
|
|
flat_buffer b;
|
|
|
|
|
parser_type<true> p;
|
|
|
|
|
p.eager(true);
|
|
|
|
|
ostream(b) <<
|
2016-11-20 07:32:41 -05:00
|
|
|
"PUT / HTTP/1.1\r\n"
|
|
|
|
|
"Transfer-Encoding: chunked\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
"1\r\n"
|
|
|
|
|
"*";
|
2017-05-31 08:01:55 -07:00
|
|
|
auto used = p.put(b.data(), ec);
|
|
|
|
|
b.consume(used);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(! ec);
|
|
|
|
|
BEAST_EXPECT(! p.is_done());
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(p.get().body() == "*");
|
2017-05-31 08:01:55 -07:00
|
|
|
ostream(b) <<
|
|
|
|
|
"\r\n"
|
|
|
|
|
"0;d;e=3;f=\"4\"\r\n"
|
2016-11-20 07:32:41 -05:00
|
|
|
"Expires: never\r\n"
|
|
|
|
|
"MD5-Fingerprint: -\r\n";
|
|
|
|
|
// incomplete parse, missing the final crlf
|
2017-05-31 08:01:55 -07:00
|
|
|
used = p.put(b.data(), ec);
|
|
|
|
|
b.consume(used);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(ec == error::need_more);
|
2019-01-20 09:50:43 -08:00
|
|
|
ec = {};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(! p.is_done());
|
2017-05-31 08:01:55 -07:00
|
|
|
ostream(b) <<
|
|
|
|
|
"\r\n"; // final crlf to end message
|
|
|
|
|
used = p.put(b.data(), ec);
|
|
|
|
|
b.consume(used);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECTS(! ec, ec.message());
|
|
|
|
|
BEAST_EXPECT(p.is_done());
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
2017-05-31 08:01:55 -07:00
|
|
|
// skip body
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
|
|
|
|
error_code ec;
|
2017-06-03 08:56:21 -07:00
|
|
|
response_parser<string_body> p;
|
2017-05-31 08:01:55 -07:00
|
|
|
p.skip(true);
|
|
|
|
|
p.put(buf(
|
2016-11-20 07:32:41 -05:00
|
|
|
"HTTP/1.1 200 OK\r\n"
|
2017-05-31 08:01:55 -07:00
|
|
|
"Content-Length: 5\r\n"
|
2016-11-20 07:32:41 -05:00
|
|
|
"\r\n"
|
2017-05-31 08:01:55 -07:00
|
|
|
"*****")
|
|
|
|
|
, ec);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECTS(! ec, ec.message());
|
|
|
|
|
BEAST_EXPECT(p.is_done());
|
|
|
|
|
BEAST_EXPECT(p.is_header_done());
|
|
|
|
|
BEAST_EXPECT(p.content_length() &&
|
2017-05-31 08:01:55 -07:00
|
|
|
*p.content_length() == 5);
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
template<class DynamicBuffer>
|
|
|
|
|
void
|
|
|
|
|
testNeedMore()
|
|
|
|
|
{
|
|
|
|
|
error_code ec;
|
|
|
|
|
std::size_t used;
|
|
|
|
|
{
|
|
|
|
|
DynamicBuffer b;
|
|
|
|
|
parser_type<true> p;
|
|
|
|
|
ostream(b) <<
|
|
|
|
|
"GET / HTTP/1.1\r\n";
|
|
|
|
|
used = p.put(b.data(), ec);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECTS(ec == error::need_more, ec.message());
|
2017-05-31 08:01:55 -07:00
|
|
|
b.consume(used);
|
2019-01-20 09:50:43 -08:00
|
|
|
ec = {};
|
2017-05-31 08:01:55 -07:00
|
|
|
ostream(b) <<
|
|
|
|
|
"User-Agent: test\r\n"
|
|
|
|
|
"\r\n";
|
|
|
|
|
used = p.put(b.data(), ec);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECTS(! ec, ec.message());
|
2017-05-31 08:01:55 -07:00
|
|
|
b.consume(used);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(p.is_done());
|
|
|
|
|
BEAST_EXPECT(p.is_header_done());
|
2017-05-31 08:01:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
testGotSome()
|
|
|
|
|
{
|
|
|
|
|
error_code ec;
|
|
|
|
|
parser_type<true> p;
|
|
|
|
|
auto used = p.put(buf(""), ec);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(ec == error::need_more);
|
|
|
|
|
BEAST_EXPECT(! p.got_some());
|
|
|
|
|
BEAST_EXPECT(used == 0);
|
2019-01-20 09:50:43 -08:00
|
|
|
ec = {};
|
2017-05-31 08:01:55 -07:00
|
|
|
used = p.put(buf("G"), ec);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(ec == error::need_more);
|
|
|
|
|
BEAST_EXPECT(p.got_some());
|
|
|
|
|
BEAST_EXPECT(used == 0);
|
2017-05-31 08:01:55 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-16 12:09:20 -07:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 08:49:25 -07:00
|
|
|
void
|
|
|
|
|
testIssue1187()
|
|
|
|
|
{
|
|
|
|
|
// make sure parser finishes on redirect
|
|
|
|
|
error_code ec;
|
|
|
|
|
parser_type<false> p;
|
|
|
|
|
p.eager(true);
|
|
|
|
|
p.put(buf(
|
|
|
|
|
"HTTP/1.1 301 Moved Permanently\r\n"
|
|
|
|
|
"Location: https://www.ebay.com\r\n"
|
|
|
|
|
"\r\n\r\n"), ec);
|
|
|
|
|
BEAST_EXPECTS(! ec, ec.message());
|
|
|
|
|
BEAST_EXPECT(p.is_header_done());
|
|
|
|
|
BEAST_EXPECT(! p.is_done());
|
|
|
|
|
BEAST_EXPECT(p.need_eof());
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 16:45:05 +01:00
|
|
|
void
|
|
|
|
|
testIssue1880()
|
|
|
|
|
{
|
|
|
|
|
// A user raised the issue that multiple Content-Length fields and
|
|
|
|
|
// values are permissible provided all values are the same.
|
|
|
|
|
// See rfc7230 section-3.3.2
|
|
|
|
|
// https://tools.ietf.org/html/rfc7230#section-3.3.2
|
|
|
|
|
// Credit: Dimitry Bulsunov
|
|
|
|
|
|
|
|
|
|
auto checkPass = [&](std::string const& message)
|
|
|
|
|
{
|
|
|
|
|
response_parser<string_body> parser;
|
|
|
|
|
error_code ec;
|
|
|
|
|
parser.put(net::buffer(message), ec);
|
|
|
|
|
BEAST_EXPECTS(!ec.failed(), ec.message());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto checkFail = [&](std::string const& message)
|
|
|
|
|
{
|
|
|
|
|
response_parser<string_body> parser;
|
|
|
|
|
error_code ec;
|
|
|
|
|
parser.put(net::buffer(message), ec);
|
|
|
|
|
BEAST_EXPECTS(ec == error::bad_content_length, ec.message());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// multiple contents lengths the same
|
|
|
|
|
checkPass(
|
|
|
|
|
"HTTP/1.1 200 OK\r\n"
|
|
|
|
|
"Content-Length: 0\r\n"
|
|
|
|
|
"Content-Length: 0\r\n"
|
|
|
|
|
"\r\n");
|
|
|
|
|
|
|
|
|
|
// multiple contents lengths different
|
|
|
|
|
checkFail(
|
|
|
|
|
"HTTP/1.1 200 OK\r\n"
|
|
|
|
|
"Content-Length: 0\r\n"
|
|
|
|
|
"Content-Length: 1\r\n"
|
|
|
|
|
"\r\n");
|
|
|
|
|
|
|
|
|
|
// multiple content in same header
|
|
|
|
|
checkPass(
|
|
|
|
|
"HTTP/1.1 200 OK\r\n"
|
|
|
|
|
"Content-Length: 0, 0, 0\r\n"
|
|
|
|
|
"\r\n");
|
|
|
|
|
|
|
|
|
|
// multiple content in same header but mismatch (case 1)
|
|
|
|
|
checkFail(
|
|
|
|
|
"HTTP/1.1 200 OK\r\n"
|
|
|
|
|
"Content-Length: 0, 0, 1\r\n"
|
|
|
|
|
"\r\n");
|
|
|
|
|
|
|
|
|
|
// multiple content in same header but mismatch (case 2)
|
|
|
|
|
checkFail(
|
|
|
|
|
"HTTP/1.1 200 OK\r\n"
|
|
|
|
|
"Content-Length: 0, 0, 0\r\n"
|
|
|
|
|
"Content-Length: 1\r\n"
|
|
|
|
|
"\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:32:41 -05:00
|
|
|
void
|
|
|
|
|
run() override
|
|
|
|
|
{
|
|
|
|
|
testParse();
|
2017-05-31 08:01:55 -07:00
|
|
|
testNeedMore<flat_buffer>();
|
|
|
|
|
testNeedMore<multi_buffer>();
|
|
|
|
|
testGotSome();
|
2017-10-16 12:09:20 -07:00
|
|
|
testIssue818();
|
2018-07-12 08:49:25 -07:00
|
|
|
testIssue1187();
|
2020-03-18 16:45:05 +01:00
|
|
|
testIssue1880();
|
2016-11-20 07:32:41 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-01 17:01:57 -07:00
|
|
|
BEAST_DEFINE_TESTSUITE(beast,http,parser);
|
2016-11-20 07:32:41 -05:00
|
|
|
|
|
|
|
|
} // http
|
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|