forked from boostorg/beast
Refactor treatment of status code and obsolete reason (API Change):
fix #398 A new enum status is added for the status code. The function obsolete_reason returns default reason phrasing. If a response has an empty reason, the serializer will automatically insert the default reason phrase for the status code.
This commit is contained in:
@@ -53,6 +53,7 @@ unit-test http-tests :
|
||||
http/read.cpp
|
||||
http/rfc7230.cpp
|
||||
http/serializer.cpp
|
||||
http/status.cpp
|
||||
http/string_body.cpp
|
||||
http/type_traits.cpp
|
||||
http/verb.cpp
|
||||
|
||||
@@ -23,6 +23,7 @@ add_executable (http-tests
|
||||
read.cpp
|
||||
rfc7230.cpp
|
||||
serializer.cpp
|
||||
status.cpp
|
||||
string_body.cpp
|
||||
type_traits.cpp
|
||||
verb.cpp
|
||||
|
||||
@@ -296,13 +296,6 @@ public:
|
||||
}();
|
||||
}
|
||||
|
||||
void
|
||||
testReasonString()
|
||||
{
|
||||
for(int i = 1; i <= 999; ++i)
|
||||
BEAST_EXPECT(! reason_string(i).empty());
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@@ -312,7 +305,6 @@ public:
|
||||
testPrepare();
|
||||
testSwap();
|
||||
testSpecialMembers();
|
||||
testReasonString();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// 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/status.hpp>
|
||||
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
|
||||
namespace beast {
|
||||
namespace http {
|
||||
|
||||
class status_test
|
||||
: public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void
|
||||
testStatus()
|
||||
{
|
||||
auto const good =
|
||||
[&](status v)
|
||||
{
|
||||
BEAST_EXPECT(obsolete_reason(v) != "Unknown Status");
|
||||
};
|
||||
good(status::continue_);
|
||||
good(status::switching_protocols);
|
||||
good(status::processing);
|
||||
good(status::ok);
|
||||
good(status::created);
|
||||
good(status::accepted);
|
||||
good(status::non_authoritative_information);
|
||||
good(status::no_content);
|
||||
good(status::reset_content);
|
||||
good(status::partial_content);
|
||||
good(status::multi_status);
|
||||
good(status::already_reported);
|
||||
good(status::im_used);
|
||||
good(status::multiple_choices);
|
||||
good(status::moved_permanently);
|
||||
good(status::found);
|
||||
good(status::see_other);
|
||||
good(status::not_modified);
|
||||
good(status::use_proxy);
|
||||
good(status::temporary_redirect);
|
||||
good(status::permanent_redirect);
|
||||
good(status::bad_request);
|
||||
good(status::unauthorized);
|
||||
good(status::payment_required);
|
||||
good(status::forbidden);
|
||||
good(status::not_found);
|
||||
good(status::method_not_allowed);
|
||||
good(status::not_acceptable);
|
||||
good(status::proxy_authentication_required);
|
||||
good(status::request_timeout);
|
||||
good(status::conflict);
|
||||
good(status::gone);
|
||||
good(status::length_required);
|
||||
good(status::precondition_failed);
|
||||
good(status::payload_too_large);
|
||||
good(status::uri_too_long);
|
||||
good(status::unsupported_media_type);
|
||||
good(status::range_not_satisfiable);
|
||||
good(status::expectation_failed);
|
||||
good(status::misdirected_request);
|
||||
good(status::unprocessable_entity);
|
||||
good(status::locked);
|
||||
good(status::failed_dependency);
|
||||
good(status::upgrade_required);
|
||||
good(status::precondition_required);
|
||||
good(status::too_many_requests);
|
||||
good(status::request_header_fields_too_large);
|
||||
good(status::unavailable_for_legal_reasons);
|
||||
good(status::internal_server_error);
|
||||
good(status::not_implemented);
|
||||
good(status::bad_gateway);
|
||||
good(status::service_unavailable);
|
||||
good(status::gateway_timeout);
|
||||
good(status::http_version_not_supported);
|
||||
good(status::variant_also_negotiates);
|
||||
good(status::insufficient_storage);
|
||||
good(status::loop_detected);
|
||||
good(status::not_extended);
|
||||
good(status::network_authentication_required);
|
||||
}
|
||||
|
||||
void
|
||||
run()
|
||||
{
|
||||
testStatus();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(status,http,beast);
|
||||
|
||||
} // http
|
||||
} // beast
|
||||
|
||||
Reference in New Issue
Block a user