Skip to content

Commit d98578e

Browse files
committed
Refactor deflate/inflate code in serializer and parser
1 parent 2d6bc80 commit d98578e

25 files changed

+464
-1061
lines changed

include/boost/http_proto.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <boost/http_proto/rfc/upgrade_rule.hpp>
5555

5656
#include <boost/http_proto/service/service.hpp>
57-
#include <boost/http_proto/service/zlib_service.hpp>
57+
#include <boost/http_proto/service/deflate_service.hpp>
58+
#include <boost/http_proto/service/inflate_service.hpp>
5859

5960
#endif

include/boost/http_proto/detail/workspace.hpp

Lines changed: 10 additions & 0 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)
@@ -128,6 +129,15 @@ class workspace
128129
reserve_front(
129130
std::size_t n);
130131

132+
/** Convert unused storage to reserved storage.
133+
134+
@return nullptr if n >= this->size()
135+
*/
136+
BOOST_HTTP_PROTO_DECL
137+
unsigned char*
138+
try_reserve_front(
139+
std::size_t n) noexcept;
140+
131141
template<class T, class... Args>
132142
typename std::decay<T>::type&
133143
emplace(Args&&... args);

include/boost/http_proto/message_view_base.hpp

Lines changed: 1 addition & 4 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)
@@ -13,10 +14,6 @@
1314

1415
#include <boost/http_proto/detail/config.hpp>
1516
#include <boost/http_proto/fields_view_base.hpp>
16-
#include <boost/url/grammar/recycled.hpp>
17-
#include <boost/url/grammar/type_traits.hpp>
18-
#include <memory>
19-
#include <string>
2017

2118
namespace boost {
2219
namespace http_proto {

include/boost/http_proto/parser.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class parser
268268
to @ref parse completes with an error code
269269
equal to @ref condition::need_more_input.
270270
271-
@returns A non-empty mutable buffer.
271+
@return A non-empty mutable buffer.
272272
273273
@see
274274
@ref commit,
@@ -535,6 +535,8 @@ class parser
535535
private:
536536
friend class request_parser;
537537
friend class response_parser;
538+
friend class parser_service;
539+
class filter;
538540

539541
BOOST_HTTP_PROTO_DECL
540542
parser(context&, detail::kind);
@@ -602,7 +604,7 @@ class parser
602604
buffers::mutable_buffer_pair mbp_;
603605
buffers::const_buffer_pair cbp_;
604606

605-
detail::filter* filter_;
607+
filter* filter_;
606608
buffers::any_dynamic_buffer* eb_;
607609
sink* sink_;
608610

include/boost/http_proto/serializer.hpp

Lines changed: 3 additions & 6 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)
@@ -24,7 +25,6 @@
2425
#include <boost/buffers/type_traits.hpp>
2526
#include <boost/system/result.hpp>
2627

27-
#include <memory>
2828
#include <numeric>
2929
#include <type_traits>
3030
#include <utility>
@@ -34,9 +34,6 @@ namespace http_proto {
3434

3535
#ifndef BOOST_HTTP_PROTO_DOCS
3636
class message_view_base;
37-
namespace detail {
38-
class filter;
39-
} // namespace detail
4037
#endif
4138

4239
/** A serializer for HTTP/1 messages
@@ -219,8 +216,8 @@ class serializer
219216
consume(std::size_t n);
220217

221218
private:
219+
class filter;
222220
class const_buf_gen_base;
223-
224221
template<class>
225222
class const_buf_gen;
226223

@@ -288,7 +285,7 @@ class serializer
288285
detail::workspace ws_;
289286

290287
const_buf_gen_base* buf_gen_;
291-
detail::filter* filter_;
288+
filter* filter_;
292289
source* source_;
293290

294291
buffers::circular_buffer cb0_;

include/boost/http_proto/service/deflate_service.hpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,26 @@ namespace zlib {
2121

2222
/** Provides the ZLib compression API
2323
*/
24-
struct deflate_service
24+
25+
struct BOOST_SYMBOL_VISIBLE
26+
deflate_service
27+
: public http_proto::service
2528
{
2629
virtual char const* version() const noexcept = 0;
27-
virtual int init(stream_t& st, int level) const = 0;
28-
virtual int init2(stream_t& st, int level, int method,
30+
virtual int init(stream& st, int level) const = 0;
31+
virtual int init2(stream& st, int level, int method,
2932
int windowBits, int memLevel, int strategy) const = 0;
30-
virtual int set_dict(stream_t& st, unsigned char const* dict, unsigned len) const = 0;
31-
virtual int get_dict(stream_t& st, unsigned char* dest, unsigned* len) const = 0;
32-
virtual int dup(stream_t& dest, stream_t& src) const = 0;
33-
virtual int deflate(stream_t& st, int flush) const = 0;
34-
virtual int deflate_end(stream_t& st) const = 0;
35-
virtual int reset(stream_t& st) const = 0;
36-
virtual int params(stream_t& st, int level, int strategy) const = 0;
37-
virtual std::size_t bound(stream_t& st, unsigned long sourceLen) const = 0;
38-
virtual int pending(stream_t& st, unsigned* pending, int* bits) const = 0;
39-
virtual int prime(stream_t& st, int bits, int value) const = 0;
40-
virtual int set_header(stream_t& st, void* header) const = 0;
33+
virtual int set_dict(stream& st, unsigned char const* dict, unsigned len) const = 0;
34+
virtual int get_dict(stream& st, unsigned char* dest, unsigned* len) const = 0;
35+
virtual int dup(stream& dest, stream& src) const = 0;
36+
virtual int deflate(stream& st, int flush) const = 0;
37+
virtual int deflate_end(stream& st) const = 0;
38+
virtual int reset(stream& st) const = 0;
39+
virtual int params(stream& st, int level, int strategy) const = 0;
40+
virtual std::size_t bound(stream& st, unsigned long sourceLen) const = 0;
41+
virtual int pending(stream& st, unsigned* pending, int* bits) const = 0;
42+
virtual int prime(stream& st, int bits, int value) const = 0;
43+
virtual int set_header(stream& st, void* header) const = 0;
4144
};
4245

4346
BOOST_HTTP_PROTO_ZLIB_DECL

include/boost/http_proto/service/inflate_service.hpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// Copyright (c) 2025 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,24 +20,26 @@ namespace zlib {
1920

2021
/** Provides the ZLib decompression API
2122
*/
22-
struct inflate_service
23+
struct BOOST_SYMBOL_VISIBLE
24+
inflate_service
25+
: public http_proto::service
2326
{
2427
virtual char const* version() const noexcept = 0;
25-
virtual int init(stream_t& st) const = 0;
26-
virtual int init2(stream_t& st, int windowBits) const = 0;
27-
virtual int inflate(stream_t& st, int flush) const = 0;
28-
virtual int inflate_end(stream_t& st) const = 0;
29-
virtual int set_dict(stream_t& st, unsigned char const* dict, unsigned len) const = 0;
30-
virtual int get_dict(stream_t& st, unsigned char* dest, unsigned* len) const = 0;
31-
virtual int sync(stream_t& st) const = 0;
32-
virtual int dup(stream_t& dest, stream_t& src) const = 0;
33-
virtual int reset(stream_t& st) const = 0;
34-
virtual int reset2(stream_t& st, int windowBits) const = 0;
35-
virtual int prime(stream_t& st, int bits, int value) const = 0;
36-
virtual long mark(stream_t& st) const = 0;
37-
virtual int get_header(stream_t& st, void* header) const = 0;
38-
virtual int back_init(stream_t& st, int windowBits, unsigned char* window) const = 0;
39-
virtual int back_end(stream_t& st) const = 0;
28+
virtual int init(stream& st) const = 0;
29+
virtual int init2(stream& st, int windowBits) const = 0;
30+
virtual int inflate(stream& st, int flush) const = 0;
31+
virtual int inflate_end(stream& st) const = 0;
32+
virtual int set_dict(stream& st, unsigned char const* dict, unsigned len) const = 0;
33+
virtual int get_dict(stream& st, unsigned char* dest, unsigned* len) const = 0;
34+
virtual int sync(stream& st) const = 0;
35+
virtual int dup(stream& dest, stream& src) const = 0;
36+
virtual int reset(stream& st) const = 0;
37+
virtual int reset2(stream& st, int windowBits) const = 0;
38+
virtual int prime(stream& st, int bits, int value) const = 0;
39+
virtual long mark(stream& st) const = 0;
40+
virtual int get_header(stream& st, void* header) const = 0;
41+
virtual int back_init(stream& st, int windowBits, unsigned char* window) const = 0;
42+
virtual int back_end(stream& st) const = 0;
4043
virtual unsigned long compile_flags() const = 0;
4144
};
4245

0 commit comments

Comments
 (0)