Skip to content

Commit e6330db

Browse files
committed
Remove max_capacity_in_bytes from detail::header
1 parent f15657c commit e6330db

File tree

14 files changed

+150
-283
lines changed

14 files changed

+150
-283
lines changed

include/boost/http_proto/detail/align_up.hpp

Lines changed: 0 additions & 32 deletions
This file was deleted.

include/boost/http_proto/detail/config.hpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3+
// Copyright (c) 2025 Mohammad Nejati
34
//
45
// Distributed under the Boost Software License, Version 1.0. (See accompanying
56
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -19,52 +20,26 @@ namespace http_proto {
1920

2021
//------------------------------------------------
2122

22-
#if defined(BOOST_HTTP_PROTO_DOCS)
23-
# define BOOST_HTTP_PROTO_DECL
24-
#else
2523
# if (defined(BOOST_HTTP_PROTO_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)) && !defined(BOOST_HTTP_PROTO_STATIC_LINK)
2624
# if defined(BOOST_HTTP_PROTO_SOURCE)
2725
# define BOOST_HTTP_PROTO_DECL BOOST_SYMBOL_EXPORT
2826
# define BOOST_HTTP_PROTO_BUILD_DLL
2927
# else
3028
# define BOOST_HTTP_PROTO_DECL BOOST_SYMBOL_IMPORT
3129
# endif
32-
33-
# if defined(BOOST_HTTP_PROTO_ZLIB_SOURCE)
34-
# define BOOST_HTTP_PROTO_ZLIB_DECL BOOST_SYMBOL_EXPORT
35-
# define BOOST_HTTP_PROTO_ZLIB_BUILD_DLL
36-
# else
37-
# define BOOST_HTTP_PROTO_ZLIB_DECL BOOST_SYMBOL_IMPORT
38-
# endif
39-
40-
# if defined(BOOST_HTTP_PROTO_EXT_SOURCE)
41-
# define BOOST_HTTP_PROTO_EXT_DECL BOOST_SYMBOL_EXPORT
42-
# define BOOST_HTTP_PROTO_EXT_BUILD_DLL
43-
# else
44-
# define BOOST_HTTP_PROTO_EXT_DECL BOOST_SYMBOL_IMPORT
45-
# endif
4630
# endif // shared lib
4731

4832
# ifndef BOOST_HTTP_PROTO_DECL
4933
# define BOOST_HTTP_PROTO_DECL
5034
# endif
5135

52-
# ifndef BOOST_HTTP_PROTO_ZLIB_DECL
53-
# define BOOST_HTTP_PROTO_ZLIB_DECL
54-
# endif
55-
56-
# ifndef BOOST_HTTP_PROTO_EXT_DECL
57-
# define BOOST_HTTP_PROTO_EXT_DECL
58-
# endif
59-
6036
# if !defined(BOOST_HTTP_PROTO_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_HTTP_PROTO_NO_LIB)
6137
# define BOOST_LIB_NAME boost_http_proto
6238
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_HTTP_PROTO_DYN_LINK)
6339
# define BOOST_DYN_LINK
6440
# endif
6541
# include <boost/config/auto_link.hpp>
6642
# endif
67-
#endif
6843

6944
//------------------------------------------------
7045

@@ -74,17 +49,6 @@ namespace http_proto {
7449
# define BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND
7550
#endif
7651

77-
// holds any offset within headers
78-
using offset_type = ::uint32_t; // private
79-
80-
// maximum size of http header,
81-
// chunk header, or chunk extensions
82-
#ifndef BOOST_HTTP_PROTO_MAX_HEADER
83-
#define BOOST_HTTP_PROTO_MAX_HEADER (offset_type(-1))
84-
#endif
85-
static constexpr auto max_offset =
86-
BOOST_HTTP_PROTO_MAX_HEADER;
87-
8852
// Add source location to error codes
8953
#ifdef BOOST_HTTP_PROTO_NO_SOURCE_LOCATION
9054
# define BOOST_HTTP_PROTO_ERR(ev) (::boost::system::error_code(ev))

include/boost/http_proto/detail/header.hpp

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#ifndef BOOST_HTTP_PROTO_DETAIL_HEADER_HPP
1212
#define BOOST_HTTP_PROTO_DETAIL_HEADER_HPP
1313

14-
#include <boost/http_proto/detail/align_up.hpp>
1514
#include <boost/http_proto/detail/config.hpp>
1615
#include <boost/http_proto/error.hpp>
1716
#include <boost/http_proto/field.hpp>
@@ -52,6 +51,17 @@ struct header
5251
// ^ ^ ^ ^
5352
// buf buf+prefix buf+size buf+cap
5453

54+
#ifdef BOOST_HTTP_PROTO_TEST_FORCE_8BIT_OFFSET
55+
using offset_type = std::uint8_t;
56+
#else
57+
using offset_type = std::uint32_t;
58+
#endif
59+
60+
static
61+
constexpr
62+
std::size_t max_offset =
63+
std::numeric_limits<offset_type>::max();
64+
5565
struct entry
5666
{
5767
offset_type np; // name pos
@@ -66,42 +76,6 @@ struct header
6676
std::size_t dv) const noexcept;
6777
};
6878

69-
// HTTP-message = start-line CRLF *( field-line CRLF ) CRLF
70-
// start-line = request-line / status-line
71-
// status-line = HTTP-version SP status-code SP [ reason-phrase ]
72-
// status-code = 3DIGIT
73-
// HTTP-name = %x48.54.54.50 ; HTTP
74-
// HTTP-version = HTTP-name "/" DIGIT "." DIGIT
75-
//
76-
// => "HTTP/1.1 111 \r\n" + trailing "\r\n"
77-
static
78-
constexpr
79-
std::size_t const min_status_line = 17;
80-
81-
// "X:\r\n"
82-
static
83-
constexpr
84-
std::size_t const min_field_line = 4;
85-
86-
static
87-
constexpr
88-
std::size_t const max_field_lines =
89-
(max_offset - min_status_line) / min_field_line;
90-
91-
/** Returns the largest permissible capacity in bytes
92-
*/
93-
static
94-
constexpr
95-
std::size_t
96-
max_capacity_in_bytes() noexcept
97-
{
98-
// the entire serialized contents of the header
99-
// must fit entirely in max_offset
100-
return align_up(
101-
(max_offset + (max_field_lines * sizeof(entry))),
102-
alignof(entry));
103-
}
104-
10579
struct table
10680
{
10781
explicit
@@ -148,7 +122,8 @@ struct header
148122
char const* cbuf = nullptr;
149123
char* buf = nullptr;
150124
std::size_t cap = 0;
151-
std::size_t max_cap = max_capacity_in_bytes();
125+
std::size_t max_cap =
126+
std::numeric_limits<std::size_t>::max();
152127

153128
offset_type size = 0;
154129
offset_type count = 0;

include/boost/http_proto/fields_base.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ class fields_base
4040
detail::header h_;
4141
bool static_storage = false;
4242

43+
using entry =
44+
detail::header::entry;
45+
using offset_type =
46+
detail::header::offset_type;
47+
using table =
48+
detail::header::table;
49+
4350
class op_t;
4451
class prefix_op_t
4552
{
@@ -57,11 +64,6 @@ class fields_base
5764
~prefix_op_t();
5865
};
5966

60-
using entry =
61-
detail::header::entry;
62-
using table =
63-
detail::header::table;
64-
6567
friend class fields;
6668
template<std::size_t>
6769
friend class static_fields;

include/boost/http_proto/fields_view_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class fields_view_base
166166
std::size_t
167167
max_size() noexcept
168168
{
169-
return max_offset;
169+
return detail::header::max_offset;
170170
}
171171

172172
/** Return an iterator to the beginning

src/detail/header.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
//
1010

1111
#include <boost/http_proto/detail/header.hpp>
12-
#include <boost/http_proto/detail/align_up.hpp>
1312
#include <boost/http_proto/field.hpp>
1413
#include <boost/http_proto/fields_view_base.hpp>
1514
#include <boost/http_proto/header_limits.hpp>
1615
#include <boost/http_proto/rfc/list_rule.hpp>
1716
#include <boost/http_proto/rfc/token_rule.hpp>
1817
#include <boost/http_proto/rfc/upgrade_rule.hpp>
1918
#include <boost/http_proto/rfc/detail/rules.hpp>
19+
20+
#include "../rfc/transfer_encoding_rule.hpp"
21+
2022
#include <boost/url/grammar/ci_string.hpp>
2123
#include <boost/url/grammar/parse.hpp>
2224
#include <boost/url/grammar/range_rule.hpp>
@@ -25,10 +27,9 @@
2527
#include <boost/assert.hpp>
2628
#include <boost/assert/source_location.hpp>
2729
#include <boost/static_assert.hpp>
28-
#include <string>
30+
2931
#include <utility>
3032

31-
#include "../rfc/transfer_encoding_rule.hpp"
3233

3334
namespace boost {
3435
namespace http_proto {
@@ -212,11 +213,10 @@ bytes_needed(
212213
if(size < 19)
213214
size = 19;
214215

215-
return
216-
align_up(
217-
size,
218-
alignof(header::entry)) +
219-
count * sizeof(header::entry);
216+
// align size up to alignof(entry)
217+
size = (size + alignof(entry) - 1) & ~(alignof(entry) - 1);
218+
219+
return size + count * sizeof(entry);
220220
}
221221

222222
std::size_t
@@ -1170,11 +1170,11 @@ parse_start_line(
11701170
auto sm = std::get<0>(*rv);
11711171
h.req.method = string_to_method(sm);
11721172
h.req.method_len =
1173-
static_cast<offset_type>(sm.size());
1173+
static_cast<header::offset_type>(sm.size());
11741174
// target
11751175
auto st = std::get<1>(*rv);
11761176
h.req.target_len =
1177-
static_cast<offset_type>(st.size());
1177+
static_cast<header::offset_type>(st.size());
11781178
// version
11791179
switch(std::get<2>(*rv))
11801180
{
@@ -1231,7 +1231,7 @@ parse_start_line(
12311231
std::get<1>(*rv).v);
12321232
h.res.status = std::get<1>(*rv).st;
12331233
}
1234-
h.prefix = static_cast<offset_type>(it - it0);
1234+
h.prefix = static_cast<header::offset_type>(it - it0);
12351235
h.size = h.prefix;
12361236
h.on_start_line();
12371237
}
@@ -1259,7 +1259,7 @@ parse_field(
12591259
{
12601260
// final CRLF
12611261
h.size = static_cast<
1262-
offset_type>(it - h.cbuf);
1262+
header::offset_type>(it - h.cbuf);
12631263
return;
12641264
}
12651265
if( ec == grammar::error::need_more &&
@@ -1283,7 +1283,7 @@ parse_field(
12831283
remove_obs_fold(h.buf + h.size, it);
12841284
}
12851285
auto id = string_to_field(rv->name);
1286-
h.size = static_cast<offset_type>(it - h.cbuf);
1286+
h.size = static_cast<header::offset_type>(it - h.cbuf);
12871287

12881288
// add field table entry
12891289
if(h.buf != nullptr)
@@ -1292,13 +1292,13 @@ parse_field(
12921292
h.buf + h.cap)[h.count];
12931293
auto const base =
12941294
h.buf + h.prefix;
1295-
e.np = static_cast<offset_type>(
1295+
e.np = static_cast<header::offset_type>(
12961296
rv->name.data() - base);
1297-
e.nn = static_cast<offset_type>(
1297+
e.nn = static_cast<header::offset_type>(
12981298
rv->name.size());
1299-
e.vp = static_cast<offset_type>(
1299+
e.vp = static_cast<header::offset_type>(
13001300
rv->value.data() - base);
1301-
e.vn = static_cast<offset_type>(
1301+
e.vn = static_cast<header::offset_type>(
13021302
rv->value.size());
13031303
e.id = id;
13041304
}

0 commit comments

Comments
 (0)