Skip to content

Commit 3cedee9

Browse files
committed
reintroduce string_body
1 parent a5f9dbe commit 3cedee9

4 files changed

Lines changed: 147 additions & 29 deletions

File tree

doc/modules/ROOT/pages/reference.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ cpp:boost::http_proto::response[response]
5353

5454
cpp:boost::http_proto::response_base[response_base]
5555

56-
| **Types (2/2)**
57-
5856
cpp:boost::http_proto::response_parser[response_parser]
5957

58+
| **Types (2/2)**
59+
6060
cpp:boost::http_proto::response_view[response_view]
6161

6262
cpp:boost::http_proto::serializer[serializer]
@@ -71,6 +71,8 @@ cpp:boost::http_proto::static_request[static_request]
7171

7272
cpp:boost::http_proto::static_response[static_response]
7373

74+
cpp:boost::http_proto::string_body[string_body]
75+
7476
**Functions**
7577

7678
cpp:boost::http_proto::combine_field_values[combine_field_values]

doc/tagfiles/boost-http_proto-doxygen.tag.xml

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<class kind="class">boost::http_proto::static_fields</class>
3535
<class kind="class">boost::http_proto::static_request</class>
3636
<class kind="class">boost::http_proto::static_response</class>
37+
<class kind="class">boost::http_proto::string_body</class>
3738
<class kind="class">boost::http_proto::upgrade_protocol</class>
3839
<class kind="class">boost::http_proto::condition</class>
3940
<class kind="class">boost::http_proto::content_coding</class>
@@ -206,8 +207,8 @@
206207
</member>
207208
<member kind="function">
208209
<type>void</type>
209-
<name>set_max_capacity</name>
210-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
210+
<name>set_max_capacity_in_bytes</name>
211+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
211212
<anchor/>
212213
<arglist>(std::size_t n)</arglist>
213214
</member>
@@ -322,8 +323,8 @@
322323
</member>
323324
<member kind="function">
324325
<type>void</type>
325-
<name>set_max_capacity</name>
326-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
326+
<name>set_max_capacity_in_bytes</name>
327+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
327328
<anchor/>
328329
<arglist>(std::size_t n)</arglist>
329330
</member>
@@ -493,13 +494,6 @@
493494
<compound kind="class">
494495
<name>boost::http_proto::file</name>
495496
<filename>boost/http_proto/file.adoc</filename>
496-
<member kind="function">
497-
<type>void</type>
498-
<name>~file</name>
499-
<anchorfile>boost/http_proto/file/2destructor.adoc</anchorfile>
500-
<anchor/>
501-
<arglist>()</arglist>
502-
</member>
503497
<member kind="function">
504498
<type>file&amp;</type>
505499
<name>operator=</name>
@@ -735,8 +729,8 @@
735729
</member>
736730
<member kind="function">
737731
<type>void</type>
738-
<name>set_max_capacity</name>
739-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
732+
<name>set_max_capacity_in_bytes</name>
733+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
740734
<anchor/>
741735
<arglist>(std::size_t n)</arglist>
742736
</member>
@@ -1382,8 +1376,8 @@
13821376
</member>
13831377
<member kind="function">
13841378
<type>void</type>
1385-
<name>set_max_capacity</name>
1386-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
1379+
<name>set_max_capacity_in_bytes</name>
1380+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
13871381
<anchor/>
13881382
<arglist>(std::size_t n)</arglist>
13891383
</member>
@@ -1603,8 +1597,8 @@
16031597
</member>
16041598
<member kind="function">
16051599
<type>void</type>
1606-
<name>set_max_capacity</name>
1607-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
1600+
<name>set_max_capacity_in_bytes</name>
1601+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
16081602
<anchor/>
16091603
<arglist>(std::size_t n)</arglist>
16101604
</member>
@@ -2077,8 +2071,8 @@
20772071
</member>
20782072
<member kind="function">
20792073
<type>void</type>
2080-
<name>set_max_capacity</name>
2081-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
2074+
<name>set_max_capacity_in_bytes</name>
2075+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
20822076
<anchor/>
20832077
<arglist>(std::size_t n)</arglist>
20842078
</member>
@@ -2277,8 +2271,8 @@
22772271
</member>
22782272
<member kind="function">
22792273
<type>void</type>
2280-
<name>set_max_capacity</name>
2281-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
2274+
<name>set_max_capacity_in_bytes</name>
2275+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
22822276
<anchor/>
22832277
<arglist>(std::size_t n)</arglist>
22842278
</member>
@@ -2840,8 +2834,8 @@
28402834
</member>
28412835
<member kind="function">
28422836
<type>void</type>
2843-
<name>set_max_capacity</name>
2844-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
2837+
<name>set_max_capacity_in_bytes</name>
2838+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
28452839
<anchor/>
28462840
<arglist>(std::size_t n)</arglist>
28472841
</member>
@@ -3019,8 +3013,8 @@
30193013
</member>
30203014
<member kind="function">
30213015
<type>void</type>
3022-
<name>set_max_capacity</name>
3023-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
3016+
<name>set_max_capacity_in_bytes</name>
3017+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
30243018
<anchor/>
30253019
<arglist>(std::size_t n)</arglist>
30263020
</member>
@@ -3219,8 +3213,8 @@
32193213
</member>
32203214
<member kind="function">
32213215
<type>void</type>
3222-
<name>set_max_capacity</name>
3223-
<anchorfile>boost/http_proto/fields_base/set_max_capacity.adoc</anchorfile>
3216+
<name>set_max_capacity_in_bytes</name>
3217+
<anchorfile>boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc</anchorfile>
32243218
<anchor/>
32253219
<arglist>(std::size_t n)</arglist>
32263220
</member>
@@ -3281,6 +3275,24 @@
32813275
<arglist>()</arglist>
32823276
</member>
32833277
</compound>
3278+
<compound kind="class">
3279+
<name>boost::http_proto::string_body</name>
3280+
<filename>boost/http_proto/string_body.adoc</filename>
3281+
<member kind="function">
3282+
<type>const_iterator</type>
3283+
<name>begin</name>
3284+
<anchorfile>boost/http_proto/string_body/begin.adoc</anchorfile>
3285+
<anchor/>
3286+
<arglist>()</arglist>
3287+
</member>
3288+
<member kind="function">
3289+
<type>const_iterator</type>
3290+
<name>end</name>
3291+
<anchorfile>boost/http_proto/string_body/end.adoc</anchorfile>
3292+
<anchor/>
3293+
<arglist>()</arglist>
3294+
</member>
3295+
</compound>
32843296
<compound kind="class">
32853297
<name>boost::http_proto::upgrade_protocol</name>
32863298
<filename>boost/http_proto/upgrade_protocol.adoc</filename>

include/boost/http_proto.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <boost/http_proto/static_request.hpp>
3939
#include <boost/http_proto/static_response.hpp>
4040
#include <boost/http_proto/status.hpp>
41+
#include <boost/http_proto/string_body.hpp>
4142
#include <boost/http_proto/version.hpp>
4243

4344
#include <boost/http_proto/rfc/combine_field_values.hpp>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
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+
#ifndef BOOST_HTTP_PROTO_STRING_BODY_HPP
11+
#define BOOST_HTTP_PROTO_STRING_BODY_HPP
12+
13+
#include <boost/http_proto/detail/config.hpp>
14+
#include <boost/buffers/const_buffer.hpp>
15+
#include <string>
16+
#include <utility>
17+
18+
namespace boost {
19+
namespace http_proto {
20+
21+
/** A ConstBufferSequence adapter for an owned `std::string`.
22+
23+
Takes ownership of a `std::string` and exposes
24+
it via an interface conforming to the
25+
ConstBufferSequence requirements.
26+
27+
@par Example
28+
@code
29+
serializer sr(ctx);
30+
response res(status::not_found);
31+
32+
std::string body =
33+
"<html>\n"
34+
" <body>\n"
35+
" <h1>404 Not Found</h1>\n"
36+
" <p>Sorry, the page does not exist.</p>\n"
37+
" </body>\n"
38+
"</html>\n";
39+
sr.start<string_body>(res, std::move(body));
40+
@endcode
41+
42+
@see
43+
@ref serializer.
44+
*/
45+
class string_body
46+
{
47+
std::string s_;
48+
buffers::const_buffer cb_;
49+
50+
public:
51+
/// The type for each buffer.
52+
using value_type = buffers::const_buffer;
53+
54+
/// The type of a const iterator.
55+
using const_iterator = buffers::const_buffer const*;
56+
57+
string_body(
58+
string_body&& other) noexcept
59+
: s_(std::move(other.s_))
60+
, cb_(s_.data(), s_.size())
61+
{
62+
other.cb_ = {};
63+
}
64+
65+
/** Constructor.
66+
*/
67+
string_body(
68+
string_body const& other) = delete;
69+
70+
/** Constructor.
71+
72+
@param s The string to take ownership of.
73+
*/
74+
string_body(
75+
std::string s) noexcept
76+
: s_(std::move(s))
77+
, cb_(s_.data(), s_.size())
78+
{
79+
}
80+
81+
/** Return an iterator to the beginning of the
82+
buffer sequence.
83+
*/
84+
const_iterator
85+
begin() const noexcept
86+
{
87+
return &cb_;
88+
}
89+
90+
/** Return an iterator to the end of the
91+
buffer sequence.
92+
*/
93+
const_iterator
94+
end() const noexcept
95+
{
96+
return &cb_ + 1;
97+
}
98+
};
99+
100+
} // http_proto
101+
} // boost
102+
103+
#endif

0 commit comments

Comments
 (0)