Line data Source code
1 : //
2 : // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot 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/server/route_handler.hpp>
11 : #include <boost/http/string_body.hpp>
12 : #include <boost/capy/ex/async_run.hpp>
13 :
14 : namespace boost {
15 : namespace http {
16 :
17 1 : route_params::
18 : ~route_params()
19 : {
20 1 : }
21 :
22 : route_params&
23 0 : route_params::
24 : status(
25 : http::status code)
26 : {
27 0 : res.set_start_line(code, res.version());
28 0 : return *this;
29 : }
30 :
31 : route_params&
32 0 : route_params::
33 : set_body(std::string s)
34 : {
35 0 : if(! res.exists(http::field::content_type))
36 : {
37 : // VFALCO TODO detect Content-Type
38 0 : res.set(http::field::content_type,
39 : "text/plain; charset=UTF-8");
40 : }
41 :
42 0 : if(! res.exists(field::content_length))
43 : {
44 0 : res.set_payload_size(s.size());
45 : }
46 :
47 0 : serializer.start(res,
48 0 : http::string_body(std::string(s)));
49 :
50 0 : return *this;
51 : }
52 :
53 : auto
54 0 : route_params::
55 : spawn(
56 : capy::task<route_result> t) ->
57 : route_result
58 : {
59 0 : return this->suspend(
60 0 : [ex = this->ex, t = std::move(t)](resumer resume) mutable
61 : {
62 0 : capy::async_run(ex)(std::move(t),
63 0 : [resume](route_result rv)
64 : {
65 0 : resume(rv);
66 0 : },
67 0 : [resume](std::exception_ptr ep)
68 : {
69 0 : resume(ep);
70 0 : });
71 0 : });
72 : }
73 :
74 : } // http
75 : } // boost
|