LCOV - code coverage report
Current view: top level - http/common - http_response.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 1 1
Test Date: 2026-02-20 15:38:22 Functions: 50.0 % 2 1

            Line data    Source code
       1              : #ifndef HTTP_RESPONSE_HPP
       2              : #define HTTP_RESPONSE_HPP
       3              : 
       4              : #include <string>
       5              : #include <vector>
       6              : #include <boost/asio.hpp>
       7              : #include <boost/asio/buffer.hpp>
       8              : #include <boost/lexical_cast.hpp>
       9              : #include "../data/out_data.hpp"
      10              : #include "headers.hpp"
      11              : 
      12              : namespace thinger::http {
      13              : 
      14              : class http_response : public headers {
      15              : 
      16              : public:
      17              : 
      18              :     // the status of the http_response.
      19              :     enum class status {
      20              :         ok = 200,
      21              :         created = 201,
      22              :         accepted = 202,
      23              :         no_content = 204,
      24              :         multiple_choices = 300,
      25              :         moved_permanently = 301,
      26              :         moved_temporarily = 302,
      27              :         not_modified = 304,
      28              :         temporary_redirect = 307,
      29              :         permanent_redirect = 308,
      30              :         bad_request = 400,
      31              :         unauthorized = 401,
      32              :         forbidden = 403,
      33              :         not_found = 404,
      34              :         not_allowed = 405,
      35              :         timed_out = 408,
      36              :         conflict = 409,
      37              :         payload_too_large = 413,
      38              :         upgrade_required = 426,
      39              :         too_many_requests = 429,
      40              :         internal_server_error = 500,
      41              :         not_implemented = 501,
      42              :         bad_gateway = 502,
      43              :         service_unavailable = 503,
      44              :         switching_protocols = 101
      45              :     } ;
      46              : 
      47              :     // constructor
      48              :     http_response();
      49         1891 :     ~http_response() override = default;
      50              : 
      51              :     // response to buffer
      52              :     void to_buffer(std::vector<boost::asio::const_buffer>&buffer) const override;
      53              : 
      54              :     // some setters
      55              :     void set_content(std::string content);
      56              :     void set_content(std::string content, std::string content_type);
      57              :     void set_content_length(size_t content_length);
      58              :     void set_content_type(std::string && content_type);
      59              : 
      60              :     void set_content_type(const std::string &content_type);
      61              : 
      62              :     void set_status(uint16_t status_code);
      63              :     void set_status(status status_code);
      64              :     void set_reason_phrase(const std::string& reason);
      65              : 
      66              :     // some getters
      67              :     const std::string& get_content() const;
      68              :     std::string& get_content();
      69              :     size_t get_content_size() const;
      70              :     size_t get_size() override;
      71              :     status get_status() const;
      72              :     int get_status_code() const;
      73              :     bool is_ok() const;
      74              :     bool is_redirect_response() const;
      75              : 
      76              :     // log
      77              :     void log(const char* scope, int level) const override;
      78              : 
      79              :     // factory methods
      80              :     static std::shared_ptr<http_response> stock_http_reply(http_response::status status);
      81              : 
      82              : private:
      83              :     std::string content_;
      84              :     status status_ = status::ok;
      85              :     std::string reason_phrase_;
      86              : };
      87              : 
      88              : }
      89              : 
      90              : #endif
        

Generated by: LCOV version 2.0-1