mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
New classes are introduced to represent HTTP messages and their associated bodies. The parser interface is reworked to use CRTP, error codes, and trait checks. New classes: * basic_headers Models field/value pairs in a HTTP message. * message Models a HTTP message, body behavior defined by template argument. Parsed message carries metadata generated during parsing. * parser Produces parsed messages. * empty_body, string_body, basic_streambuf_body Classes used to represent content bodies in various ways. New functions: * read, async_read, write, async_write Read and write HTTP messages on a socket. New concepts: * Body: Represents the HTTP Content-Body. * Field: A HTTP header field. * FieldSequence: A forward sequence of fields. * Reader: Parses a Body from a stream of bytes. * Writer: Serializes a Body to buffers. basic_parser changes: * add write methods which throw exceptions instead * error_code passed via parameter instead of return value * fold private member calls into existing callbacks * basic_parser uses CRTP instead of virtual members * add documentation on Derived requirements for CRTP impl/http-parser changes: * joyent renamed to nodejs to reflect upstream changes
64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
//
|
|
// 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.
|
|
#include <beast/http/basic_headers.h>
|
|
|
|
#include <beast/unit_test/suite.h>
|
|
|
|
namespace beast {
|
|
namespace http {
|
|
namespace test {
|
|
|
|
class basic_headers_test : public unit_test::suite
|
|
{
|
|
public:
|
|
template<class Allocator>
|
|
using bha = basic_headers<Allocator>;
|
|
|
|
using bh = basic_headers<std::allocator<char>>;
|
|
|
|
template<class Allocator>
|
|
static
|
|
void
|
|
fill(std::size_t n, basic_headers<Allocator>& h)
|
|
{
|
|
for(std::size_t i = 1; i<= n; ++i)
|
|
h.insert(std::to_string(i), i);
|
|
}
|
|
|
|
void testHeaders()
|
|
{
|
|
bh h1;
|
|
expect(h1.empty());
|
|
fill(1, h1);
|
|
expect(h1.size() == 1);
|
|
bh h2;
|
|
h2 = h1;
|
|
expect(h2.size() == 1);
|
|
h2.insert("2", "2");
|
|
expect(std::distance(h2.begin(), h2.end()) == 2);
|
|
h1 = std::move(h2);
|
|
expect(h1.size() == 2);
|
|
expect(h2.size() == 0);
|
|
bh h3(std::move(h1));
|
|
expect(h3.size() == 2);
|
|
expect(h1.size() == 0);
|
|
}
|
|
|
|
void run() override
|
|
{
|
|
testHeaders();
|
|
}
|
|
};
|
|
|
|
BEAST_DEFINE_TESTSUITE(basic_headers,http,beast);
|
|
|
|
} // test
|
|
} // asio
|
|
} // beast
|