message::version is a member function (API Change):

fix #778

* The version data member is replaced with accessor
  member functions.

Actions Required:

* Call member function message::version instead of accessing
  the version member at call sites.
This commit is contained in:
Vinnie Falco committed 2017-09-12 17:13:02 -07:00
1 parent 54fe7cacf7
commit 38e28966ea
33 files changed
+218 -178

No files matched your search

+3 -15
View File
@@ -100,7 +100,7 @@ swap(
swap(
static_cast<Fields&>(h1),
static_cast<Fields&>(h2));
swap(h1.version, h2.version);
swap(h1.version_, h2.version_);
swap(h1.method_, h2.method_);
}
@@ -115,18 +115,6 @@ header(Arg1&& arg1, ArgN&&... argn)
{
}
#if 0
template<class Fields>
template<class... Args>
header<false, Fields>::
header(status result, unsigned version_, Args&&... args)
: Fields(std::forward<Args>(args)...)
, version(version_)
, result_(result)
{
}
#endif
template<class Fields>
inline
status
@@ -198,7 +186,7 @@ swap(
swap(
static_cast<Fields&>(h1),
static_cast<Fields&>(h2));
swap(h1.version, h2.version);
swap(h1.version_, h2.version_);
swap(h1.result_, h2.result_);
}
@@ -378,7 +366,7 @@ prepare_payload(std::true_type)
this->chunked(false);
}
}
else if(this->version >= 11)
else if(this->version() >= 11)
{
this->chunked(true);
}
+2 -2
View File
@@ -27,7 +27,7 @@ void
serializer<isRequest, Body, Fields>::
frdinit(std::true_type)
{
frd_.emplace(m_, m_.version, m_.method());
frd_.emplace(m_, m_.version(), m_.method());
}
template<
@@ -36,7 +36,7 @@ void
serializer<isRequest, Body, Fields>::
frdinit(std::false_type)
{
frd_.emplace(m_, m_.version, m_.result_int());
frd_.emplace(m_, m_.version(), m_.result_int());
}
template<
+84 -38
View File
@@ -18,6 +18,7 @@
#include <boost/beast/core/string.hpp>
#include <boost/beast/core/detail/empty_base_optimization.hpp>
#include <boost/beast/core/detail/integer_sequence.hpp>
#include <boost/assert.hpp>
#include <boost/optional.hpp>
#include <boost/throw_exception.hpp>
#include <memory>
@@ -69,7 +70,22 @@ struct header<true, Fields> : Fields
/// The type representing the fields.
using fields_type = Fields;
/** The HTTP-version.
/// COnstructor
header() = default;
/// Constructor
header(header&&) = default;
/// Constructor
header(header const&) = default;
/// Assignment
header& operator=(header&&) = default;
/// Assignment
header& operator=(header const&) = default;
/** Return the HTTP-version.
This holds both the major and minor version numbers,
using these formulas:
@@ -80,22 +96,29 @@ struct header<true, Fields> : Fields
Newly constructed headers will use HTTP/1.1 by default.
*/
unsigned version = 11;
unsigned version() const noexcept
{
return version_;
}
/// Default constructor
header() = default;
/** Set the HTTP-version.
/// Move constructor
header(header&&) = default;
This holds both the major and minor version numbers,
using these formulas:
@code
unsigned major = version / 10;
unsigned minor = version % 10;
@endcode
/// Copy constructor
header(header const&) = default;
Newly constructed headers will use HTTP/1.1 by default.
/// Move assignment
header& operator=(header&&) = default;
/// Copy assignment
header& operator=(header const&) = default;
@param value The version number to use
*/
void version(unsigned value) noexcept
{
BOOST_ASSERT(value > 0 && value < 100);
version_ = value;
}
/** Return the request-method verb.
@@ -206,15 +229,16 @@ private:
header(
verb method,
string_view target_,
unsigned version_,
unsigned version_value,
FieldsArgs&&... fields_args)
: Fields(std::forward<FieldsArgs>(fields_args)...)
, version(version_)
, method_(method)
{
version(version_value);
target(target_);
}
unsigned version_ = 11;
verb method_ = verb::unknown;
};
@@ -234,33 +258,19 @@ struct header<false, Fields> : Fields
/// The type representing the fields.
using fields_type = Fields;
/** The HTTP version.
This holds both the major and minor version numbers,
using these formulas:
@code
unsigned major = version / 10;
unsigned minor = version % 10;
@endcode
Newly constructed headers will use HTTP/1.1 by default
unless otherwise specified.
*/
unsigned version = 11;
/// Default constructor.
/// Constructor.
header() = default;
/// Move constructor
/// Constructor
header(header&&) = default;
/// Copy constructor
/// Constructor
header(header const&) = default;
/// Move assignment
/// Assignment
header& operator=(header&&) = default;
/// Copy assignment
/// Assignment
header& operator=(header const&) = default;
/** Constructor
@@ -282,6 +292,41 @@ struct header<false, Fields> : Fields
>::type>
explicit
header(Arg1&& arg1, ArgN&&... argn);
/** Return the HTTP-version.
This holds both the major and minor version numbers,
using these formulas:
@code
unsigned major = version / 10;
unsigned minor = version % 10;
@endcode
Newly constructed headers will use HTTP/1.1 by default.
*/
unsigned version() const noexcept
{
return version_;
}
/** Set the HTTP-version.
This holds both the major and minor version numbers,
using these formulas:
@code
unsigned major = version / 10;
unsigned minor = version % 10;
@endcode
Newly constructed headers will use HTTP/1.1 by default.
@param value The version number to use
*/
void version(unsigned value) noexcept
{
BOOST_ASSERT(value > 0 && value < 100);
version_ = value;
}
#endif
/** The response status-code result.
@@ -372,14 +417,15 @@ private:
template<class... FieldsArgs>
header(
status result,
unsigned version_,
unsigned version_value,
FieldsArgs&&... fields_args)
: Fields(std::forward<FieldsArgs>(fields_args)...)
, version(version_)
, result_(result)
{
version(version_value);
}
unsigned version_ = 11;
status result_ = status::ok;
#endif
};
@@ -703,7 +749,7 @@ struct message
bool
keep_alive() const
{
return this->get_keep_alive_impl(this->version);
return this->get_keep_alive_impl(this->version());
}
/** Set the keep-alive message semantic option
@@ -719,7 +765,7 @@ struct message
void
keep_alive(bool value)
{
this->set_keep_alive_impl(this->version, value);
this->set_keep_alive_impl(this->version(), value);
}
/** Returns the payload size of the body in octets if possible.
+2 -2
View File
@@ -324,7 +324,7 @@ private:
{
ec = error::bad_alloc;
}
m_.version = version;
m_.version(version);
}
void
@@ -335,7 +335,7 @@ private:
error_code& ec)
{
m_.result(code);
m_.version = version;
m_.version(version);
try
{
m_.reason(reason);
@@ -22,7 +22,7 @@ bool
is_upgrade(http::header<true,
http::basic_fields<Allocator>> const& req)
{
if(req.version < 11)
if(req.version() < 11)
return false;
if(req.method() != http::verb::get)
return false;
@@ -523,7 +523,7 @@ build_request(detail::sec_ws_key_type& key,
{
request_type req;
req.target(target);
req.version = 11;
req.version(11);
req.method(http::verb::get);
req.set(http::field::host, host);
req.set(http::field::upgrade, "websocket");
@@ -575,14 +575,14 @@ build_response(http::request<Body,
[&](std::string const& text)
{
response_type res;
res.version = req.version;
res.version(req.version());
res.result(http::status::bad_request);
res.body() = text;
res.prepare_payload();
decorate(res);
return res;
};
if(req.version < 11)
if(req.version() < 11)
return err("HTTP version 1.1 required");
if(req.method() != http::verb::get)
return err("Wrong method");
@@ -604,7 +604,7 @@ build_response(http::request<Body,
{
response_type res;
res.result(http::status::upgrade_required);
res.version = req.version;
res.version(req.version());
res.set(http::field::sec_websocket_version, "13");
res.prepare_payload();
decorate(res);
@@ -620,7 +620,7 @@ build_response(http::request<Body,
pmd_negotiate(res, unused, offer, pmd_opts_);
}
res.result(http::status::switching_protocols);
res.version = req.version;
res.version(req.version());
res.set(http::field::upgrade, "websocket");
res.set(http::field::connection, "upgrade");
{
@@ -640,7 +640,7 @@ on_response(response_type const& res,
{
bool const success = [&]()
{
if(res.version < 11)
if(res.version() < 11)
return false;
if(res.result() != http::status::switching_protocols)
return false;
+4 -2
View File
@@ -3329,12 +3329,14 @@ public:
@param fin `true` if this is the last part of the message.
@param buffers The input buffer sequence holding the data to write.
@param ec Set to indicate what error occurred, if any.
@return The number of bytes written from the buffers.
If an error occurred, this will be less than the sum
of the buffer sizes.
@param ec Set to indicate what error occurred, if any.
@return The number of bytes consumed in the input buffers.
*/
template<class ConstBufferSequence>