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 : #include <boost/http_proto/response_base.hpp>
11 :
12 : #include <cstring>
13 :
14 : namespace boost {
15 : namespace http_proto {
16 :
17 : void
18 39 : response_base::
19 : set_start_line_impl(
20 : http_proto::status sc,
21 : unsigned short si,
22 : core::string_view rs,
23 : http_proto::version v)
24 : {
25 : // TODO: check validity
26 39 : auto const vs = to_string(v);
27 : auto const new_prefix =
28 39 : vs.size() + 1 + // HTTP-version SP
29 39 : 3 + 1 + // status-code SP
30 39 : rs.size() + 2; // reason-phrase CRLF
31 :
32 : // Introduce a new scope so that prefix_op's
33 : // destructor runs before h_.on_start_line().
34 : {
35 39 : auto op = prefix_op_t(*this, new_prefix, &rs);
36 38 : char* dest = h_.buf;
37 :
38 38 : h_.version = v;
39 38 : vs.copy(dest, vs.size());
40 38 : dest += vs.size();
41 38 : *dest++ = ' ';
42 :
43 38 : h_.res.status = sc;
44 38 : h_.res.status_int = si;
45 38 : dest[0] = '0' + ((h_.res.status_int / 100) % 10);
46 38 : dest[1] = '0' + ((h_.res.status_int / 10) % 10);
47 38 : dest[2] = '0' + ((h_.res.status_int / 1) % 10);
48 38 : dest[3] = ' ';
49 38 : dest += 4;
50 :
51 38 : std::memmove(dest, rs.data(), rs.size());
52 38 : dest += rs.size();
53 38 : dest[0] = '\r';
54 38 : dest[1] = '\n';
55 38 : }
56 :
57 38 : h_.on_start_line();
58 38 : }
59 :
60 : } // http_proto
61 : } // boost
|