LCOV - code coverage report
Current view: top level - libs/http_proto/src/server - route_handler.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 15.4 % 13 2
Test Date: 2025-12-30 20:59:33 Functions: 33.3 % 3 1

            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_proto
       8              : //
       9              : 
      10              : #include <boost/http_proto/server/route_handler.hpp>
      11              : #include <boost/http_proto/string_body.hpp>
      12              : 
      13              : namespace boost {
      14              : namespace http_proto {
      15              : 
      16            1 : route_params::
      17              : ~route_params()
      18              : {
      19            1 : }
      20              : 
      21              : route_params&
      22            0 : route_params::
      23              : status(
      24              :     http_proto::status code)
      25              : {
      26            0 :     res.set_start_line(code, res.version());
      27            0 :     return *this;
      28              : }
      29              : 
      30              : route_params&
      31            0 : route_params::
      32              : set_body(std::string s)
      33              : {
      34            0 :     if(! res.exists(http_proto::field::content_type))
      35              :     {
      36              :         // VFALCO TODO detect Content-Type
      37            0 :         res.set(http_proto::field::content_type,
      38              :             "text/plain; charset=UTF-8");
      39              :     }
      40              : 
      41            0 :     if(! res.exists(field::content_length))
      42              :     {
      43            0 :         res.set_payload_size(s.size());
      44              :     }
      45              : 
      46            0 :     serializer.start(res,
      47            0 :         http_proto::string_body(std::string(s)));
      48              : 
      49            0 :     return *this;
      50              : }
      51              : 
      52              : #ifdef BOOST_HTTP_PROTO_HAS_CORO
      53              : 
      54              : auto
      55              : route_params::
      56              : spawn(
      57              :     capy::task<route_result> t) ->
      58              :         route_result
      59              : {
      60              :     return this->suspend(
      61              :         [ex = this->ex, t = std::move(t)](resumer resume) mutable
      62              :         {
      63              :             auto h = t.release();
      64              : 
      65              :             h.promise().on_done = [resume, h]()
      66              :             {
      67              :                 auto& r = h.promise().result;
      68              :                 if(r.index() == 2)
      69              :                 {
      70              :                     auto ep = std::get<2>(r);
      71              :                     h.destroy();
      72              :                     resume(ep);
      73              :                     return;
      74              :                 }
      75              :                 auto rv = std::move(std::get<1>(r));
      76              :                 auto resume_ = resume; // would be destroyed
      77              :                 h.destroy();
      78              :                 resume_(rv);
      79              :             };
      80              : 
      81              :             ex.post([h]() { h.resume(); });
      82              :         });
      83              : }
      84              : 
      85              : #endif
      86              : 
      87              : } // http_proto
      88              : } // boost
        

Generated by: LCOV version 2.1