| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | ✗ | route_params:: | |
| 24 | status( | ||
| 25 | http::status code) | ||
| 26 | { | ||
| 27 | ✗ | res.set_start_line(code, res.version()); | |
| 28 | ✗ | return *this; | |
| 29 | } | ||
| 30 | |||
| 31 | route_params& | ||
| 32 | ✗ | route_params:: | |
| 33 | set_body(std::string s) | ||
| 34 | { | ||
| 35 | ✗ | if(! res.exists(http::field::content_type)) | |
| 36 | { | ||
| 37 | // VFALCO TODO detect Content-Type | ||
| 38 | ✗ | res.set(http::field::content_type, | |
| 39 | "text/plain; charset=UTF-8"); | ||
| 40 | } | ||
| 41 | |||
| 42 | ✗ | if(! res.exists(field::content_length)) | |
| 43 | { | ||
| 44 | ✗ | res.set_payload_size(s.size()); | |
| 45 | } | ||
| 46 | |||
| 47 | ✗ | serializer.start(res, | |
| 48 | ✗ | http::string_body(std::string(s))); | |
| 49 | |||
| 50 | ✗ | return *this; | |
| 51 | } | ||
| 52 | |||
| 53 | auto | ||
| 54 | ✗ | route_params:: | |
| 55 | spawn( | ||
| 56 | capy::task<route_result> t) -> | ||
| 57 | route_result | ||
| 58 | { | ||
| 59 | ✗ | return this->suspend( | |
| 60 | ✗ | [ex = this->ex, t = std::move(t)](resumer resume) mutable | |
| 61 | { | ||
| 62 | ✗ | capy::async_run(ex)(std::move(t), | |
| 63 | ✗ | [resume](route_result rv) | |
| 64 | { | ||
| 65 | ✗ | resume(rv); | |
| 66 | ✗ | }, | |
| 67 | ✗ | [resume](std::exception_ptr ep) | |
| 68 | { | ||
| 69 | ✗ | resume(ep); | |
| 70 | ✗ | }); | |
| 71 | ✗ | }); | |
| 72 | } | ||
| 73 | |||
| 74 | } // http | ||
| 75 | } // boost | ||
| 76 |