Skip to content

Commit 4d82d81

Browse files
committed
Add static fields and message containers
1 parent 7777782 commit 4d82d81

33 files changed

Lines changed: 2637 additions & 667 deletions

cmake/toolchains/gcc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
include(${CMAKE_CURRENT_LIST_DIR}/common.cmake)
33

44
# Compiler options.
5-
add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter)
5+
add_compile_options(-Wall -Wextra -Wpedantic)

include/boost/http_proto.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#include <boost/http_proto/serializer.hpp>
3939
#include <boost/http_proto/sink.hpp>
4040
#include <boost/http_proto/source.hpp>
41+
#include <boost/http_proto/static_fields.hpp>
42+
#include <boost/http_proto/static_request.hpp>
43+
#include <boost/http_proto/static_response.hpp>
4144
#include <boost/http_proto/status.hpp>
4245
#include <boost/http_proto/string_body.hpp>
4346
#include <boost/http_proto/version.hpp>

include/boost/http_proto/detail/header.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ struct empty
4646

4747
struct header
4848
{
49-
// this field lookup table is
50-
// stored at the end of the
51-
// allocated buffer, in
52-
// reverse order.
49+
// +------------+-----------+--------------+------------------------------+
50+
// | start-line | headers | free space | entry[count-1] ... entry[0] |
51+
// +------------+-----------+--------------+------------------------------+
52+
// ^ ^ ^ ^
53+
// buf buf+prefix buf+size buf+cap
54+
5355
struct entry
5456
{
5557
offset_type np; // name pos

include/boost/http_proto/detail/impl/workspace.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct workspace::any
3030
};
3131

3232
template<class U>
33-
struct alignas(alignof(::max_align_t))
33+
struct alignas(::max_align_t)
3434
workspace::any_impl : any
3535
{
3636
U u;
@@ -117,7 +117,7 @@ push_array(
117117
std::size_t n,
118118
T const& t)
119119
{
120-
struct alignas(alignof(::max_align_t))
120+
struct alignas(::max_align_t)
121121
U : any
122122
{
123123
std::size_t n_ = 0;

include/boost/http_proto/detail/sv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace detail {
2121
namespace string_literals {
2222
inline
2323
core::string_view
24-
operator"" _sv(
24+
operator""_sv(
2525
char const* p,
2626
std::size_t n) noexcept
2727
{

include/boost/http_proto/fields_base.hpp

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//
22
// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
33
// Copyright (c) 2024 Christian Mazakas
4+
// Copyright (c) 2025 Mohammad Nejati
45
//
56
// Distributed under the Boost Software License, Version 1.0. (See accompanying
67
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -37,43 +38,90 @@ class fields_base
3738
: public virtual fields_view_base
3839
{
3940
detail::header h_;
41+
bool static_storage = false;
4042

4143
class op_t;
44+
class prefix_op_t
45+
{
46+
fields_base& self_;
47+
offset_type new_prefix_;
48+
char* buf_ = nullptr;
49+
50+
public:
51+
prefix_op_t(
52+
fields_base& self,
53+
std::size_t new_prefix,
54+
core::string_view* s0 = nullptr,
55+
core::string_view* s1 = nullptr);
56+
57+
~prefix_op_t();
58+
};
59+
4260
using entry =
4361
detail::header::entry;
4462
using table =
4563
detail::header::table;
4664

4765
friend class fields;
66+
template<std::size_t>
67+
friend class static_fields;
68+
friend class request_base;
4869
friend class request;
70+
template<std::size_t>
71+
friend class static_request;
72+
friend class response_base;
4973
friend class response;
74+
template<std::size_t>
75+
friend class static_response;
5076
friend class serializer;
5177
friend class message_base;
5278
friend struct detail::header;
5379
friend struct detail::prefix_op;
5480

81+
BOOST_HTTP_PROTO_DECL
82+
explicit
83+
fields_base(
84+
detail::kind) noexcept;
85+
5586
BOOST_HTTP_PROTO_DECL
5687
fields_base(
5788
detail::kind,
58-
std::size_t size);
89+
char*,
90+
std::size_t) noexcept;
5991

6092
BOOST_HTTP_PROTO_DECL
6193
fields_base(
6294
detail::kind,
63-
std::size_t size,
64-
std::size_t max_size);
95+
std::size_t);
6596

6697
BOOST_HTTP_PROTO_DECL
67-
explicit
6898
fields_base(
69-
detail::kind) noexcept;
99+
detail::kind,
100+
std::size_t,
101+
std::size_t);
70102

71103
BOOST_HTTP_PROTO_DECL
72104
fields_base(
73105
detail::kind,
74106
core::string_view);
75107

76-
fields_base(detail::header const&);
108+
BOOST_HTTP_PROTO_DECL
109+
fields_base(
110+
detail::kind,
111+
char*,
112+
std::size_t,
113+
core::string_view);
114+
115+
BOOST_HTTP_PROTO_DECL
116+
explicit
117+
fields_base(
118+
detail::header const&);
119+
120+
BOOST_HTTP_PROTO_DECL
121+
fields_base(
122+
detail::header const&,
123+
char*,
124+
std::size_t);
77125

78126
public:
79127
/** Destructor

include/boost/http_proto/fields_view.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class BOOST_SYMBOL_VISIBLE
2424
: public fields_view_base
2525
{
2626
friend class fields;
27+
template<std::size_t>
28+
friend class static_fields;
2729

2830
#ifndef BOOST_HTTP_PROTO_DOCS
2931
protected:

include/boost/http_proto/fields_view_base.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,21 @@ class fields_view_base
3232
detail::header const* ph_;
3333

3434
friend class fields;
35+
template<std::size_t>
36+
friend class static_fields;
3537
friend class fields_base;
3638
friend class fields_view;
3739
friend class message_base;
3840
friend class message_view_base;
41+
friend class request_base;
3942
friend class request;
43+
template<std::size_t>
44+
friend class static_request;
4045
friend class request_view;
46+
friend class response_base;
4147
friend class response;
48+
template<std::size_t>
49+
friend class static_response;
4250
friend class response_view;
4351
friend class serializer;
4452

include/boost/http_proto/message_base.hpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class message_base
2525
: public fields_base
2626
, public message_view_base
2727
{
28-
friend class request;
29-
friend class response;
28+
friend class request_base;
29+
friend class response_base;
3030

3131
explicit
3232
message_base(
@@ -37,6 +37,16 @@ class message_base
3737
{
3838
}
3939

40+
message_base(
41+
detail::kind k,
42+
char* storage,
43+
std::size_t storage_size) noexcept
44+
: fields_view_base(&this->fields_base::h_)
45+
, fields_base(
46+
k, storage, storage_size)
47+
{
48+
}
49+
4050
message_base(
4151
detail::kind k,
4252
std::size_t storage_size)
@@ -67,15 +77,37 @@ class message_base
6777
{
6878
}
6979

80+
message_base(
81+
detail::kind k,
82+
char* storage,
83+
std::size_t storage_size,
84+
core::string_view s)
85+
: fields_view_base(
86+
&this->fields_base::h_)
87+
, fields_base(
88+
k, storage, storage_size, s)
89+
{
90+
}
91+
7092
explicit
7193
message_base(
72-
detail::header const& ph) noexcept
94+
detail::header const& ph)
7395
: fields_view_base(
7496
&this->fields_base::h_)
7597
, fields_base(ph)
7698
{
7799
}
78100

101+
message_base(
102+
detail::header const& ph,
103+
char* storage,
104+
std::size_t storage_size)
105+
: fields_view_base(
106+
&this->fields_base::h_)
107+
, fields_base(ph, storage, storage_size)
108+
{
109+
}
110+
79111
public:
80112
//--------------------------------------------
81113
//

0 commit comments

Comments
 (0)