Initialize Writer in prepare:

Writer requires a call to Writer::init to call content_length. This
changes prepare to correctly call init. A consequences is that
prepare can now throw unexpectedly for user-defined writers that
can fail their initialization.
This commit is contained in:
Vinnie Falco
2016-06-20 09:40:35 -04:00
parent 227c2b131d
commit 62219add69

View File

@@ -8,6 +8,7 @@
#ifndef BEAST_HTTP_IMPL_MESSAGE_V1_IPP #ifndef BEAST_HTTP_IMPL_MESSAGE_V1_IPP
#define BEAST_HTTP_IMPL_MESSAGE_V1_IPP #define BEAST_HTTP_IMPL_MESSAGE_V1_IPP
#include <beast/core/error.hpp>
#include <beast/http/rfc7230.hpp> #include <beast/http/rfc7230.hpp>
#include <beast/http/detail/has_content_length.hpp> #include <beast/http/detail/has_content_length.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
@@ -87,7 +88,11 @@ prepare_content_length(prepare_info& pi,
std::true_type) std::true_type)
{ {
typename Body::writer w(msg); typename Body::writer w(msg);
//w.init(ec); // VFALCO This is a design problem! // VFALCO This is a design problem!
error_code ec;
w.init(ec);
if(ec)
throw system_error{ec};
pi.content_length = w.content_length(); pi.content_length = w.content_length();
} }