libs/http/src/json/json_body.cpp

0.0% Lines (0/6) 0.0% Functions (0/2) 0.0% Branches (0/1)
libs/http/src/json/json_body.cpp
Line Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/http
8 //
9
10 #include <boost/http/json/json_body.hpp>
11 #include <boost/http/json/json_sink.hpp>
12 #include <boost/http/field.hpp>
13 #include <boost/http/method.hpp>
14 #include <boost/capy/io/push_to.hpp>
15 #include <boost/json/value.hpp>
16
17 namespace boost {
18 namespace http {
19
20 json_body::
21 json_body(json_body_options options) noexcept
22 : options_(std::move(options))
23 {
24 }
25
26 route_task
27 json_body::
28 operator()(route_params& p) const
29 {
30 if( ! p.is_method(method::post) ||
31 ! p.req.value_or(
32 field::content_type, "")
33 .starts_with("application/json"))
34 co_return route_next;
35
36 json_sink sink(
37 options_.storage, options_.parse_opts);
38 auto [ec, n] = co_await capy::push_to(
39 p.req_body, sink);
40 if(ec)
41 co_return route_error(ec);
42
43 p.route_data.emplace<json::value>(
44 sink.release());
45
46 co_return route_next;
47 }
48
49 } // namespace http
50 } // namespace boost
51