-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlimits.cpp
More file actions
156 lines (130 loc) · 3.52 KB
/
Copy pathlimits.cpp
File metadata and controls
156 lines (130 loc) · 3.52 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// Copyright (c) 2019 Vinnie Falco ([email protected])
// 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/detail/config.hpp>
#include <boost/http/fields.hpp>
#include <boost/http/request.hpp>
#include <boost/http/response.hpp>
#include "test_suite.hpp"
#include <stdexcept>
#include <string>
// These ensure that limits is compiled correctly
#if \
defined(BOOST_HTTP_DYN_LINK) || \
( defined(BOOST_ALL_DYN_LINK) && ! defined(BOOST_HTTP_STATIC_LINK) )
#error "Limits should not be built with shared linking."
#endif
#ifndef BOOST_HTTP_TEST_LIMITS
#error "Limits should be built with BOOST_HTTP_TEST_LIMITS."
#endif
namespace boost {
namespace http {
constexpr auto max_offset =
std::numeric_limits<std::uint8_t>::max();
class limits_test
{
static
std::string
make_str(std::size_t n)
{
return std::string(n, '*');
}
public:
void
testLimits()
{
// request
{
request req;
core::string_view const cs =
"POST HTTP/1.1\r\n"
"\r\n";
const auto remain = max_offset - cs.size();
BOOST_TEST_THROWS(
req.set_start_line(
method::post,
make_str(remain + 1),
version::http_1_1),
std::length_error);
req.set_start_line(
method::post,
make_str(remain),
version::http_1_1);
BOOST_TEST_EQ(
req.buffer().size(), max_offset);
}
// response
{
response res;
core::string_view const cs =
"HTTP/1.1 200 \r\n"
"\r\n";
const auto remain = max_offset - cs.size();
BOOST_TEST_THROWS(
res.set_start_line(
200,
make_str(remain + 1),
version::http_1_1),
std::length_error);
res.set_start_line(
200,
make_str(remain),
version::http_1_1);
BOOST_TEST_EQ(
res.buffer().size(), max_offset);
}
}
void
testFields()
{
core::string_view const cs =
": \r\n"
"\r\n";
const auto remain = max_offset - cs.size();
// append
{
fields f;
BOOST_TEST_THROWS(
f.append(
make_str(remain / 2 + 1),
make_str(remain / 2 + 1)),
std::length_error);
f.append(
make_str(remain / 2),
make_str(remain / 2 + 1));
BOOST_TEST_EQ(
f.buffer().size(), max_offset);
}
// set
{
fields f;
BOOST_TEST_THROWS(
f.set(
make_str(remain / 2 + 1),
make_str(remain / 2 + 1)),
std::length_error);
f.set(
make_str(remain / 2),
make_str(remain / 2 + 1));
BOOST_TEST_EQ(
f.buffer().size(), max_offset);
}
}
void
run()
{
testLimits();
testFields();
}
};
TEST_SUITE(
limits_test,
"boost.http.limits");
} // http
} // boost