| 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/beast2 | ||
| 8 | // | ||
| 9 | |||
| 10 | #include <boost/beast2/server/route_handler.hpp> | ||
| 11 | #include <boost/http_proto/string_body.hpp> | ||
| 12 | #include <boost/assert.hpp> | ||
| 13 | #include <cstring> | ||
| 14 | |||
| 15 | namespace boost { | ||
| 16 | namespace beast2 { | ||
| 17 | |||
| 18 | //------------------------------------------------ | ||
| 19 | |||
| 20 | namespace detail { | ||
| 21 | |||
| 22 | const char* | ||
| 23 | ✗ | route_cat_type:: | |
| 24 | name() const noexcept | ||
| 25 | { | ||
| 26 | ✗ | return "boost.http_proto.route"; | |
| 27 | } | ||
| 28 | |||
| 29 | std::string | ||
| 30 | ✗ | route_cat_type:: | |
| 31 | message(int code) const | ||
| 32 | { | ||
| 33 | ✗ | return message(code, nullptr, 0); | |
| 34 | } | ||
| 35 | |||
| 36 | char const* | ||
| 37 | ✗ | route_cat_type:: | |
| 38 | message( | ||
| 39 | int code, | ||
| 40 | char*, | ||
| 41 | std::size_t) const noexcept | ||
| 42 | { | ||
| 43 | ✗ | switch(static_cast<route>(code)) | |
| 44 | { | ||
| 45 | ✗ | case route::send: return "http_proto::route::send"; | |
| 46 | ✗ | case route::next: return "http_proto::route::next"; | |
| 47 | ✗ | case route::close: return "http_proto::route::close"; | |
| 48 | ✗ | case route::detach: return "http_proto::route::detach"; | |
| 49 | ✗ | case route::done: return "http_proto::route::done"; | |
| 50 | ✗ | default: | |
| 51 | ✗ | return "http_proto::route::?"; | |
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | // msvc 14.0 has a bug that warns about inability | ||
| 56 | // to use constexpr construction here, even though | ||
| 57 | // there's no constexpr construction | ||
| 58 | #if defined(_MSC_VER) && _MSC_VER <= 1900 | ||
| 59 | # pragma warning( push ) | ||
| 60 | # pragma warning( disable : 4592 ) | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #if defined(__cpp_constinit) && __cpp_constinit >= 201907L | ||
| 64 | constinit route_cat_type route_cat; | ||
| 65 | #else | ||
| 66 | route_cat_type route_cat; | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #if defined(_MSC_VER) && _MSC_VER <= 1900 | ||
| 70 | # pragma warning( pop ) | ||
| 71 | #endif | ||
| 72 | |||
| 73 | } // detail | ||
| 74 | |||
| 75 | //------------------------------------------------ | ||
| 76 | |||
| 77 | Response& | ||
| 78 | ✗ | Response:: | |
| 79 | status( | ||
| 80 | http_proto::status code) | ||
| 81 | { | ||
| 82 | ✗ | m.set_start_line(code, m.version()); | |
| 83 | ✗ | return *this; | |
| 84 | } | ||
| 85 | |||
| 86 | Response& | ||
| 87 | ✗ | Response:: | |
| 88 | set_body(std::string s) | ||
| 89 | { | ||
| 90 | ✗ | if(! m.exists(http_proto::field::content_type)) | |
| 91 | { | ||
| 92 | // VFALCO TODO detect Content-Type | ||
| 93 | ✗ | m.set(http_proto::field::content_type, | |
| 94 | "text/plain; charset=UTF-8"); | ||
| 95 | } | ||
| 96 | |||
| 97 | ✗ | if(!m.exists(http_proto::field::content_length)) | |
| 98 | { | ||
| 99 | ✗ | m.set_payload_size(s.size()); | |
| 100 | } | ||
| 101 | |||
| 102 | ✗ | sr.start(m, http_proto::string_body(std::string(s))); | |
| 103 | |||
| 104 | ✗ | return *this; | |
| 105 | } | ||
| 106 | |||
| 107 | } // beast2 | ||
| 108 | } // boost | ||
| 109 |