Files
beast/test/http/error.cpp
Vinnie Falco e8be3fd7d3 New HTTP interfaces (API Change):
fix #123
fix #154
fix #265

This completely replaces the HTTP parser used to read and
parse incoming messages. The new version is faster than
the old one, and written in fewer lines. A summary of
changes:

* parse and async_parse renamed to read and async_read

* basic_parser is optimized for linear buffers,
  use flat_streambuf for the best performance with these
  functions:

  - http::read
  - http::read_some
  - http::async_read
  - http::async_read_some

* The overloads of read() and async_read() which take
  just a header have been removed, since they would
  throw away important parse metadata.

* The derived class callbacks for basic_parser have
  been streamlined. All strings passed to callbacks
  are presented in their entirety, instead of being
  provided in pieces.

These changes allow use-cases that were previously
difficult or impossible, such as:

- Efficient relaying

- Late body type commitment

- Expect: 100-continue handling
2017-07-20 08:12:15 -07:00

60 lines
1.9 KiB
C++

//
// Copyright (c) 2013-2017 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/error.hpp>
#include <beast/unit_test/suite.hpp>
#include <memory>
namespace beast {
namespace http {
class error_test : public unit_test::suite
{
public:
void
check(char const* name, error ev)
{
auto const ec = make_error_code(ev);
BEAST_EXPECT(std::string(ec.category().name()) == name);
BEAST_EXPECT(! ec.message().empty());
BEAST_EXPECT(std::addressof(ec.category()) ==
std::addressof(detail::get_http_error_category()));
BEAST_EXPECT(detail::get_http_error_category().equivalent(
static_cast<std::underlying_type<error>::type>(ev),
ec.category().default_error_condition(
static_cast<std::underlying_type<error>::type>(ev))));
BEAST_EXPECT(detail::get_http_error_category().equivalent(
ec, static_cast<std::underlying_type<error>::type>(ev)));
}
void
run() override
{
check("http", error::end_of_stream);
check("http", error::partial_message);
check("http", error::buffer_overflow);
check("http", error::bad_line_ending);
check("http", error::bad_method);
check("http", error::bad_path);
check("http", error::bad_version);
check("http", error::bad_status);
check("http", error::bad_reason);
check("http", error::bad_field);
check("http", error::bad_value);
check("http", error::bad_content_length);
check("http", error::bad_transfer_encoding);
check("http", error::bad_chunk);
}
};
BEAST_DEFINE_TESTSUITE(error,http,beast);
} // http
} // beast