Tidy up chunk decorator (API Change):

* Rename to no_chunk_decorator
* Decorator no longer has to append "\r\n" to the returned string
This commit is contained in:
Vinnie Falco committed 2017-07-20 08:12:18 -07:00
1 parent 38e9b16f75
commit 2141fabcf9
9 files changed
+49 -43

No files matched your search

@@ -134,14 +134,6 @@ chunk_crlf()
return {"\r\n", 2};
}
/// Returns a buffer sequence holding a CRLF then final chunk
inline
boost::asio::const_buffers_1
chunk_crlf_final()
{
return {"\r\n0\r\n\r\n", 7};
}
/// Returns a buffer sequence holding a final chunk header
inline
boost::asio::const_buffers_1
+9 -7
View File
@@ -73,11 +73,11 @@ write_fields(std::ostream& os,
//------------------------------------------------------------------------------
template<bool isRequest, class Body, class Fields,
class Decorator, class Allocator>
class ChunkDecorator, class Allocator>
serializer<isRequest, Body, Fields,
Decorator, Allocator>::
ChunkDecorator, Allocator>::
serializer(message<isRequest, Body, Fields> const& m,
Decorator const& d, Allocator const& alloc)
ChunkDecorator const& d, Allocator const& alloc)
: m_(m)
, d_(d)
, b_(1024, alloc)
@@ -85,11 +85,11 @@ serializer(message<isRequest, Body, Fields> const& m,
}
template<bool isRequest, class Body, class Fields,
class Decorator, class Allocator>
class ChunkDecorator, class Allocator>
template<class Visit>
void
serializer<isRequest, Body, Fields,
Decorator, Allocator>::
ChunkDecorator, Allocator>::
get(error_code& ec, Visit&& visit)
{
using boost::asio::buffer_size;
@@ -207,6 +207,7 @@ get(error_code& ec, Visit&& visit)
sv.data(), sv.size()};
}(),
detail::chunk_crlf(),
result->first,
detail::chunk_crlf()};
s_ = do_header_c;
@@ -251,6 +252,7 @@ get(error_code& ec, Visit&& visit)
sv.data(), sv.size()};
}(),
detail::chunk_crlf(),
result->first,
detail::chunk_crlf()};
s_ = do_body_c + 2;
@@ -296,10 +298,10 @@ get(error_code& ec, Visit&& visit)
}
template<bool isRequest, class Body, class Fields,
class Decorator, class Allocator>
class ChunkDecorator, class Allocator>
void
serializer<isRequest, Body, Fields,
Decorator, Allocator>::
ChunkDecorator, Allocator>::
consume(std::size_t n)
{
using boost::asio::buffer_size;
+2 -2
View File
@@ -356,12 +356,12 @@ class write_msg_op
{
Stream& s;
serializer<isRequest, Body, Fields,
empty_decorator, handler_alloc<char, Handler>> sr;
no_chunk_decorator, handler_alloc<char, Handler>> sr;
data(Handler& h, Stream& s_, message<
isRequest, Body, Fields> const& m_)
: s(s_)
, sr(m_, empty_decorator{},
, sr(m_, no_chunk_decorator{},
handler_alloc<char, Handler>{h})
{
}
+14 -12
View File
@@ -37,13 +37,13 @@ namespace http {
@see @ref serializer
*/
struct empty_decorator
struct no_chunk_decorator
{
template<class ConstBufferSequence>
string_view
operator()(ConstBufferSequence const&) const
{
return {"\r\n"};
return {};
}
string_view
@@ -115,7 +115,7 @@ struct empty_decorator
@tparam Fields The type of fields in the message.
@tparam Decorator The type of chunk decorator to use.
@tparam ChunkDecorator The type of chunk decorator to use.
@tparam Allocator The type of allocator to use.
@@ -123,7 +123,7 @@ struct empty_decorator
*/
template<
bool isRequest, class Body, class Fields,
class Decorator = empty_decorator,
class ChunkDecorator = no_chunk_decorator,
class Allocator = std::allocator<char>
>
class serializer
@@ -172,13 +172,15 @@ class serializer
using ch0_t = consuming_buffers<buffers_view<
typename buffer_type::const_buffers_type, // header
detail::chunk_header, // chunk-header
boost::asio::const_buffers_1, // chunk-ext+\r\n
boost::asio::const_buffers_1, // chunk-ext
boost::asio::const_buffers_1, // crlf
typename reader::const_buffers_type, // body
boost::asio::const_buffers_1>>; // crlf
using ch1_t = consuming_buffers<buffers_view<
detail::chunk_header, // chunk-header
boost::asio::const_buffers_1, // chunk-ext+\r\n
boost::asio::const_buffers_1, // chunk-ext
boost::asio::const_buffers_1, // crlf
typename reader::const_buffers_type, // body
boost::asio::const_buffers_1>>; // crlf
@@ -188,7 +190,7 @@ class serializer
boost::asio::const_buffers_1>>; // crlf
message<isRequest, Body, Fields> const& m_;
Decorator d_;
ChunkDecorator d_;
boost::optional<reader> rd_;
buffer_type b_;
boost::variant<boost::blank,
@@ -217,7 +219,7 @@ public:
*/
explicit
serializer(message<isRequest, Body, Fields> const& msg,
Decorator const& decorator = Decorator{},
ChunkDecorator const& decorator = ChunkDecorator{},
Allocator const& alloc = Allocator{});
/** Returns `true` if we will pause after writing the complete header.
@@ -335,18 +337,18 @@ public:
*/
template<
bool isRequest, class Body, class Fields,
class Decorator = empty_decorator,
class ChunkDecorator = no_chunk_decorator,
class Allocator = std::allocator<char>>
inline
serializer<isRequest, Body, Fields,
typename std::decay<Decorator>::type,
typename std::decay<ChunkDecorator>::type,
typename std::decay<Allocator>::type>
make_serializer(message<isRequest, Body, Fields> const& m,
Decorator const& decorator = Decorator{},
ChunkDecorator const& decorator = ChunkDecorator{},
Allocator const& allocator = Allocator{})
{
return serializer<isRequest, Body, Fields,
typename std::decay<Decorator>::type,
typename std::decay<ChunkDecorator>::type,
typename std::decay<Allocator>::type>{
m, decorator, allocator};
}