-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathresponse_base.cpp
More file actions
93 lines (80 loc) · 2.16 KB
/
response_base.cpp
File metadata and controls
93 lines (80 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Copyright (c) 2025 Mohammad Nejati
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/http
//
#include <boost/http/response_base.hpp>
#include <cstring>
namespace boost {
namespace http {
void
response_base::
set_start_line_impl(
http::status sc,
unsigned short si,
core::string_view rs,
http::version v)
{
// TODO: check validity
auto const vs = to_string(v);
auto const new_prefix =
vs.size() + 1 + // HTTP-version SP
3 + 1 + // status-code SP
rs.size() + 2; // reason-phrase CRLF
// Introduce a new scope so that prefix_op's
// destructor runs before h_.on_start_line().
{
auto op = prefix_op_t(*this, new_prefix, &rs);
char* dest = h_.buf;
h_.version = v;
vs.copy(dest, vs.size());
dest += vs.size();
*dest++ = ' ';
h_.res.status = sc;
h_.res.status_int = si;
dest[0] = '0' + ((h_.res.status_int / 100) % 10);
dest[1] = '0' + ((h_.res.status_int / 10) % 10);
dest[2] = '0' + ((h_.res.status_int / 1) % 10);
dest[3] = ' ';
dest += 4;
std::memmove(dest, rs.data(), rs.size());
dest += rs.size();
dest[0] = '\r';
dest[1] = '\n';
}
h_.on_start_line();
}
void
response_base::
set_version(
http::version v)
{
if(v == h_.version)
return;
if(h_.is_default())
{
auto def = h_.get_default(detail::kind::response);
return set_start_line_impl(
def->res.status, def->res.status_int,
core::string_view(
def->cbuf + 13, def->prefix - 15), v);
}
// Introduce a new scope so that prefix_op's
// destructor runs before h_.on_start_line().
{
auto op = prefix_op_t(
*this, h_.prefix, nullptr);
char* dest = h_.buf;
if(v == http::version::http_1_1)
dest[7] = '1';
else
dest[7] = '0';
h_.version = v;
}
h_.on_start_line();
}
} // http
} // boost