-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathjson_body.cpp
More file actions
50 lines (42 loc) · 1.17 KB
/
json_body.cpp
File metadata and controls
50 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.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)
//
// Official repository: https://github.com/cppalliance/http
//
#include <boost/http/json/json_body.hpp>
#include <boost/http/json/json_sink.hpp>
#include <boost/http/field.hpp>
#include <boost/http/method.hpp>
#include <boost/capy/io/push_to.hpp>
#include <boost/json/value.hpp>
namespace boost {
namespace http {
json_body::
json_body(json_body_options options) noexcept
: options_(std::move(options))
{
}
route_task
json_body::
operator()(route_params& p) const
{
if( ! p.is_method(method::post) ||
! p.req.value_or(
field::content_type, "")
.starts_with("application/json"))
co_return route_next;
json_sink sink(
options_.storage, options_.parse_opts);
auto [ec, n] = co_await capy::push_to(
p.req_body, sink);
if(ec)
co_return route_error(ec);
p.route_data.emplace<json::value>(
sink.release());
co_return route_next;
}
} // namespace http
} // namespace boost