2016-10-16 19:28:35 -04:00
|
|
|
//
|
|
|
|
|
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
|
|
|
//
|
|
|
|
|
// 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)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
2016-11-10 05:34:49 -05:00
|
|
|
#include <beast/http/header_parser_v1.hpp>
|
2016-10-16 19:28:35 -04:00
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
#include <beast/http/fields.hpp>
|
2016-10-16 19:28:35 -04:00
|
|
|
#include <beast/unit_test/suite.hpp>
|
|
|
|
|
#include <boost/asio/buffer.hpp>
|
|
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
class header_parser_v1_test : public beast::unit_test::suite
|
2016-10-16 19:28:35 -04:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
void testParser()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
error_code ec;
|
2016-11-10 05:34:49 -05:00
|
|
|
header_parser_v1<true, fields> p;
|
2016-10-16 19:28:35 -04:00
|
|
|
BEAST_EXPECT(! p.complete());
|
|
|
|
|
auto const n = p.write(boost::asio::buffer(
|
|
|
|
|
"GET / HTTP/1.1\r\n"
|
|
|
|
|
"User-Agent: test\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
), ec);
|
|
|
|
|
BEAST_EXPECTS(! ec, ec.message());
|
|
|
|
|
BEAST_EXPECT(p.complete());
|
|
|
|
|
BEAST_EXPECT(n == 36);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
error_code ec;
|
2016-11-10 05:34:49 -05:00
|
|
|
header_parser_v1<true, fields> p;
|
2016-10-16 19:28:35 -04:00
|
|
|
BEAST_EXPECT(! p.complete());
|
|
|
|
|
auto const n = p.write(boost::asio::buffer(
|
|
|
|
|
"GET / HTTP/1.1\r\n"
|
|
|
|
|
"User-Agent: test\r\n"
|
|
|
|
|
"Content-Length: 5\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
"*****"
|
|
|
|
|
), ec);
|
|
|
|
|
BEAST_EXPECT(n == 55);
|
|
|
|
|
BEAST_EXPECTS(! ec, ec.message());
|
|
|
|
|
BEAST_EXPECT(p.complete());
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
error_code ec;
|
2016-11-10 05:34:49 -05:00
|
|
|
header_parser_v1<false, fields> p;
|
2016-10-16 19:28:35 -04:00
|
|
|
BEAST_EXPECT(! p.complete());
|
|
|
|
|
auto const n = p.write(boost::asio::buffer(
|
|
|
|
|
"HTTP/1.1 200 OK\r\n"
|
|
|
|
|
"Server: test\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
), ec);
|
|
|
|
|
BEAST_EXPECT(n == 33);
|
|
|
|
|
BEAST_EXPECTS(! ec, ec.message());
|
|
|
|
|
BEAST_EXPECT(p.complete());
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
error_code ec;
|
2016-11-10 05:34:49 -05:00
|
|
|
header_parser_v1<false, fields> p;
|
2016-10-16 19:28:35 -04:00
|
|
|
BEAST_EXPECT(! p.complete());
|
|
|
|
|
auto const n = p.write(boost::asio::buffer(
|
|
|
|
|
"HTTP/1.1 200 OK\r\n"
|
|
|
|
|
"Server: test\r\n"
|
|
|
|
|
"Content-Length: 5\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
"*****"
|
|
|
|
|
), ec);
|
|
|
|
|
BEAST_EXPECT(n == 52);
|
|
|
|
|
BEAST_EXPECTS(! ec, ec.message());
|
|
|
|
|
BEAST_EXPECT(p.complete());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void run() override
|
|
|
|
|
{
|
|
|
|
|
testParser();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
BEAST_DEFINE_TESTSUITE(header_parser_v1,http,beast);
|
2016-10-16 19:28:35 -04:00
|
|
|
|
|
|
|
|
} // http
|
|
|
|
|
} // beast
|