diff options
| author | Rutger Broekhoff | 2026-08-28 22:22:24 +0200 |
|---|---|---|
| committer | Rutger Broekhoff | 2026-08-28 22:22:24 +0200 |
| commit | b0d7600970d2fdb1eb6fff813c7336ea34d4e228 (patch) | |
| tree | 051d6f80c7e332f4b31027025ae7c60c7ac70742 /server/src/srv.cppm | |
| parent | 70643a9e4821bd11c3f363f1708fe420965467d1 (diff) | |
| download | routemon-b0d7600970d2fdb1eb6fff813c7336ea34d4e228.tar.gz routemon-b0d7600970d2fdb1eb6fff813c7336ea34d4e228.zip | |
Indent tweaks
Diffstat (limited to 'server/src/srv.cppm')
| -rw-r--r-- | server/src/srv.cppm | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/server/src/srv.cppm b/server/src/srv.cppm index 5763bc5..aef28f4 100644 --- a/server/src/srv.cppm +++ b/server/src/srv.cppm | |||
| @@ -63,17 +63,17 @@ public: | |||
| 63 | auto unwrap() -> gpx::file&& | 63 | auto unwrap() -> gpx::file&& |
| 64 | { | 64 | { |
| 65 | return std::visit( | 65 | return std::visit( |
| 66 | util::overloaded{ | 66 | util::overloaded{ |
| 67 | [](std::exception_ptr ex) -> gpx::file&& | 67 | [](std::exception_ptr ex) -> gpx::file&& |
| 68 | { | 68 | { |
| 69 | if (ex) | 69 | if (ex) |
| 70 | std::rethrow_exception(ex); | 70 | std::rethrow_exception(ex); |
| 71 | else | 71 | else |
| 72 | throw std::runtime_error{"no GPX file parse result available"}; | 72 | throw std::runtime_error{"no GPX file parse result available"}; |
| 73 | }, | ||
| 74 | [](gpx::file&& f) -> gpx::file&& { return std::move(f); }, | ||
| 73 | }, | 75 | }, |
| 74 | [](gpx::file&& f) -> gpx::file&& { return std::move(f); }, | 76 | std::move(res_)); |
| 75 | }, | ||
| 76 | std::move(res_)); | ||
| 77 | } | 77 | } |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| @@ -100,7 +100,7 @@ struct readable_gpx_body | |||
| 100 | 100 | ||
| 101 | auto | 101 | auto |
| 102 | init(boost::optional<std::uint64_t> /* n */, beast::error_code& ec) noexcept | 102 | init(boost::optional<std::uint64_t> /* n */, beast::error_code& ec) noexcept |
| 103 | -> void | 103 | -> void |
| 104 | { | 104 | { |
| 105 | try | 105 | try |
| 106 | { | 106 | { |
| @@ -114,9 +114,9 @@ struct readable_gpx_body | |||
| 114 | } | 114 | } |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | auto put( | 117 | auto |
| 118 | beast::concepts::const_buffer_sequence auto b, | 118 | put(beast::concepts::const_buffer_sequence auto b, |
| 119 | beast::error_code& ec) noexcept -> std::size_t | 119 | beast::error_code& ec) noexcept -> std::size_t |
| 120 | { | 120 | { |
| 121 | auto total = 0uz; | 121 | auto total = 0uz; |
| 122 | try | 122 | try |
| @@ -125,7 +125,9 @@ struct readable_gpx_body | |||
| 125 | it != net::buffer_sequence_end(b); it++) | 125 | it != net::buffer_sequence_end(b); it++) |
| 126 | { | 126 | { |
| 127 | r_.put( | 127 | r_.put( |
| 128 | std::string_view{static_cast<char const*>(it->data()), it->size()}); | 128 | std::string_view{ |
| 129 | static_cast<char const*>(it->data()), it->size() | ||
| 130 | }); | ||
| 129 | total += it->size(); | 131 | total += it->size(); |
| 130 | } | 132 | } |
| 131 | ec = {}; | 133 | ec = {}; |
| @@ -166,13 +168,13 @@ public: | |||
| 166 | 168 | ||
| 167 | private: | 169 | private: |
| 168 | auto handle_process_gpx(l0_ctx ctx, http::readable_request r) | 170 | auto handle_process_gpx(l0_ctx ctx, http::readable_request r) |
| 169 | -> net::awaitable<http::presponse> | 171 | -> net::awaitable<http::presponse> |
| 170 | { | 172 | { |
| 171 | auto gpx_file = gpx::file{}; | 173 | auto gpx_file = gpx::file{}; |
| 172 | try | 174 | try |
| 173 | { | 175 | { |
| 174 | auto req = | 176 | auto req = |
| 175 | co_await http::read_request<readable_gpx_body>(ctx, std::move(r)); | 177 | co_await http::read_request<readable_gpx_body>(ctx, std::move(r)); |
| 176 | gpx_file = std::move(req->body().unwrap()); | 178 | gpx_file = std::move(req->body().unwrap()); |
| 177 | } | 179 | } |
| 178 | catch (std::exception& ex) | 180 | catch (std::exception& ex) |
| @@ -184,7 +186,7 @@ private: | |||
| 184 | .type_uri = "https://routemon.fautchen.eu/problems/gpx-parse-failed", | 186 | .type_uri = "https://routemon.fautchen.eu/problems/gpx-parse-failed", |
| 185 | }; | 187 | }; |
| 186 | co_return http::problem_rsp( | 188 | co_return http::problem_rsp( |
| 187 | ctx, tpl.instantiate(), http::keep_alive{false}); | 189 | ctx, tpl.instantiate(), http::keep_alive{false}); |
| 188 | } | 190 | } |
| 189 | 191 | ||
| 190 | // TODO: catch handler exceptions and return 500 when raised? | 192 | // TODO: catch handler exceptions and return 500 when raised? |
| @@ -199,11 +201,11 @@ private: | |||
| 199 | "internal-server-error", | 201 | "internal-server-error", |
| 200 | }; | 202 | }; |
| 201 | co_return http::problem_rsp( | 203 | co_return http::problem_rsp( |
| 202 | ctx, tpl.instantiate(), http::keep_alive{true}); | 204 | ctx, tpl.instantiate(), http::keep_alive{true}); |
| 203 | } | 205 | } |
| 204 | 206 | ||
| 205 | auto rsp = http::make_rsp<bhttp::string_body>( | 207 | auto rsp = http::make_rsp<bhttp::string_body>( |
| 206 | bhttp::status::ok, http::keep_alive{true}); | 208 | bhttp::status::ok, http::keep_alive{true}); |
| 207 | rsp.set(bhttp::field::content_type, "application/json"); | 209 | rsp.set(bhttp::field::content_type, "application/json"); |
| 208 | rsp.body() = json::serialize(json::value_from(*mres)); | 210 | rsp.body() = json::serialize(json::value_from(*mres)); |
| 209 | rsp.prepare_payload(); | 211 | rsp.prepare_payload(); |
| @@ -211,14 +213,14 @@ private: | |||
| 211 | } | 213 | } |
| 212 | 214 | ||
| 213 | auto handle_sysinfo(l0_ctx ctx, http::readable_request r) | 215 | auto handle_sysinfo(l0_ctx ctx, http::readable_request r) |
| 214 | -> net::awaitable<http::presponse> | 216 | -> net::awaitable<http::presponse> |
| 215 | { | 217 | { |
| 216 | auto req = | 218 | auto req = |
| 217 | co_await http::read_request<bhttp::empty_body>(ctx, std::move(r)); | 219 | co_await http::read_request<bhttp::empty_body>(ctx, std::move(r)); |
| 218 | auto info = inner_.sysinfo(); | 220 | auto info = inner_.sysinfo(); |
| 219 | 221 | ||
| 220 | auto rsp = http::make_rsp<bhttp::string_body>( | 222 | auto rsp = http::make_rsp<bhttp::string_body>( |
| 221 | bhttp::status::ok, http::keep_alive{true}); | 223 | bhttp::status::ok, http::keep_alive{true}); |
| 222 | rsp.set(bhttp::field::content_type, "application/json"); | 224 | rsp.set(bhttp::field::content_type, "application/json"); |
| 223 | rsp.body() = json::serialize(json::value_from(info)); | 225 | rsp.body() = json::serialize(json::value_from(info)); |
| 224 | rsp.prepare_payload(); | 226 | rsp.prepare_payload(); |
| @@ -255,13 +257,13 @@ export class server | |||
| 255 | http::server<handler::outer_ctx> srv_; | 257 | http::server<handler::outer_ctx> srv_; |
| 256 | 258 | ||
| 257 | static auto make_global_middleware() | 259 | static auto make_global_middleware() |
| 258 | -> http::middleware_t<http::base_ctx, handler::outer_ctx> | 260 | -> http::middleware_t<http::base_ctx, handler::outer_ctx> |
| 259 | { | 261 | { |
| 260 | return http::middleware_compose< | 262 | return http::middleware_compose< |
| 261 | http::base_ctx, http::trace_id_ctx<http::base_ctx>, | 263 | http::base_ctx, http::trace_id_ctx<http::base_ctx>, |
| 262 | http::trace_id_ctx<http::base_ctx>>( | 264 | http::trace_id_ctx<http::base_ctx>>( |
| 263 | http::trace_id_middleware<http::base_ctx>, | 265 | http::trace_id_middleware<http::base_ctx>, |
| 264 | http::lax_cors_middleware<http::trace_id_ctx<http::base_ctx>>); | 266 | http::lax_cors_middleware<http::trace_id_ctx<http::base_ctx>>); |
| 265 | } | 267 | } |
| 266 | 268 | ||
| 267 | public: | 269 | public: |