Skip to content

Commit 622d39b

Browse files
committed
feat: read_body
1 parent 6c0c79d commit 622d39b

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

include/boost/http_proto/parser.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ class parser
287287
parse(
288288
system::error_code& ec);
289289

290+
/** Return true if a body has been attached.
291+
*/
292+
BOOST_HTTP_PROTO_DECL
293+
bool
294+
is_body_set() const noexcept;
295+
290296
/** Attach an elastic buffer body.
291297
292298
This function attaches the specified elastic
@@ -634,10 +640,6 @@ class parser
634640
detail::workspace&
635641
ws() noexcept;
636642

637-
BOOST_HTTP_PROTO_DECL
638-
bool
639-
is_body_set() const noexcept;
640-
641643
BOOST_HTTP_PROTO_DECL
642644
void
643645
set_body_impl(buffers::any_dynamic_buffer&) noexcept;

include/boost/http_proto/server/route_handler.hpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ struct BOOST_HTTP_PROTO_SYMBOL_VISIBLE
240240
virtual void do_post();
241241

242242
std::unique_ptr<task> task_;
243+
std::function<void(void)> finish_;
243244
};
244245

245246
//-----------------------------------------------
@@ -254,22 +255,39 @@ read_body(
254255
Callback&& callback) ->
255256
route_result
256257
{
257-
(void)callback;
258-
/*
259-
return suspend(
260-
[&](resumer resume)
258+
using T = typename std::decay<ValueSink>::type;
259+
260+
struct on_finish
261261
{
262-
parser.read_body(
263-
std::forward<ValueSink>(sink),
264-
[resume, cb = std::forward<Callback>(callback)]
265-
(auto&&... args)
266-
{
267-
cb(std::forward<decltype(args)>(args)...);
268-
resume(route_result::next);
269-
});
270-
});
271-
*/
272-
return route::next;
262+
T& sink;
263+
resumer resume;
264+
typename std::decay<Callback>::type cb;
265+
266+
on_finish(
267+
T& sink_,
268+
resumer resume_,
269+
Callback&& cb_)
270+
: sink(sink_)
271+
, resume(resume_)
272+
, cb(std::forward<Callback>(cb_))
273+
{
274+
}
275+
276+
void operator()()
277+
{
278+
resume(std::move(cb)(sink.release()));
279+
}
280+
};
281+
282+
return suspend(
283+
[&](resumer resume)
284+
{
285+
finish_ = on_finish(
286+
this->parser.set_body<T>(
287+
std::forward<ValueSink>(sink)),
288+
resume,
289+
std::forward<Callback>(callback));
290+
});
273291
}
274292

275293
//-----------------------------------------------

0 commit comments

Comments
 (0)