Line data Source code
1 : //
2 : // Copyright (c) 2025 Mohammad Nejati
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 : #ifndef BOOST_HTTP_PROTO_STATIC_RESPONSE_HPP
11 : #define BOOST_HTTP_PROTO_STATIC_RESPONSE_HPP
12 :
13 : #include <boost/http_proto/response_base.hpp>
14 :
15 : namespace boost {
16 : namespace http_proto {
17 :
18 : /** A modfiable static container for HTTP responses
19 : */
20 : template<std::size_t Capacity>
21 : class static_response
22 : : public response_base
23 : {
24 : alignas(entry)
25 : char buf_[Capacity];
26 :
27 : public:
28 : /** Constructor
29 : */
30 24 : static_response() noexcept
31 24 : : fields_view_base(&this->fields_base::h_)
32 24 : , response_base(buf_, Capacity)
33 : {
34 24 : }
35 :
36 : /** Constructor
37 : */
38 : explicit
39 3 : static_response(
40 : core::string_view s)
41 3 : : fields_view_base(&this->fields_base::h_)
42 3 : , response_base(s, buf_, Capacity)
43 : {
44 3 : }
45 :
46 : /** Constructor
47 : */
48 12 : static_response(
49 : http_proto::status sc,
50 : http_proto::version v)
51 12 : : static_response()
52 : {
53 12 : if( sc != h_.res.status ||
54 4 : v != h_.version)
55 9 : set_start_line(sc, v);
56 12 : }
57 :
58 : /** Constructor
59 : *
60 : * The start-line of the response will contain the standard
61 : * text for the supplied status code and the HTTP version
62 : * will be defaulted to 1.1.
63 : */
64 : explicit
65 6 : static_response(
66 : http_proto::status sc)
67 : : static_response(
68 6 : sc, http_proto::version::http_1_1)
69 : {
70 6 : }
71 :
72 : /** Constructor
73 : */
74 2 : static_response(
75 : static_response const& other) noexcept
76 2 : : fields_view_base(&this->fields_base::h_)
77 2 : , response_base(*other.ph_, buf_, Capacity)
78 : {
79 2 : }
80 :
81 : /** Constructor
82 : */
83 2 : static_response(
84 : response_view const& other)
85 2 : : fields_view_base(&this->fields_base::h_)
86 2 : , response_base(*other.ph_, buf_, Capacity)
87 : {
88 2 : }
89 :
90 : /** Assignment
91 : */
92 : static_response&
93 1 : operator=(
94 : static_response const& other) noexcept
95 : {
96 1 : copy_impl(*other.ph_);
97 1 : return *this;
98 : }
99 :
100 : /** Assignment
101 : */
102 : static_response&
103 1 : operator=(
104 : response_view const& other)
105 : {
106 1 : copy_impl(*other.ph_);
107 1 : return *this;
108 : }
109 : };
110 :
111 : } // http_proto
112 : } // boost
113 :
114 : #endif
|