-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parser
: gzip/deflate support
#110
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c24e4ad
`deflator_filter`: use `flush::block` mode
ashtum dfeb44e
`detail::filter`: accept BufferSequence types
ashtum ae0e9de
`zlib::service`: calculate space needed for deflator/inflator
ashtum e57708d
`parser`: gzip/deflate support
ashtum 5c9dd1b
`metadata::content_encoding_t`: add unit test
ashtum 3d9bb53
`detail::filter`: handle empty buffers
ashtum d498600
`zlib_test`: zero initialize `z_stream`
ashtum 2b7377b
`zlib_service`: workaround for space overhead on s390x
ashtum fc3288d
`drone.sh`: disable ASLR
ashtum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// | ||
// Copyright (c) 2023 Vinnie Falco ([email protected]) | ||
// Copyright (c) 2024 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) | ||
|
@@ -108,19 +109,6 @@ class BOOST_HTTP_PROTO_DECL | |
buffers::const_buffer in, | ||
bool more) = 0; | ||
|
||
/** Called to process the filter. | ||
|
||
@par Preconditions | ||
@ref init was called once before any | ||
calls to `process`. | ||
*/ | ||
virtual | ||
results | ||
on_process( | ||
buffers::mutable_buffer_span out, | ||
buffers::const_buffer_span in, | ||
bool more); | ||
|
||
private: | ||
results | ||
process_impl( | ||
|
@@ -131,22 +119,13 @@ class BOOST_HTTP_PROTO_DECL | |
return on_process(out, in, more); | ||
} | ||
|
||
results | ||
process_impl( | ||
buffers::mutable_buffer_span const& out, | ||
buffers::const_buffer_span const& in, | ||
bool more) | ||
{ | ||
return on_process(out, in, more); | ||
} | ||
|
||
template< | ||
class MutableBuffers, | ||
class ConstBuffers> | ||
class MutableBufferSequence, | ||
class ConstBufferSequence> | ||
results | ||
process_impl( | ||
MutableBuffers const& out, | ||
ConstBuffers const& in, | ||
MutableBufferSequence const& out, | ||
ConstBufferSequence const& in, | ||
bool more); | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// | ||
// Copyright (c) 2023 Vinnie Falco ([email protected]) | ||
// Copyright (c) 2024 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) | ||
|
@@ -10,92 +11,61 @@ | |
#ifndef BOOST_HTTP_PROTO_DETAIL_IMPL_FILTER_HPP | ||
#define BOOST_HTTP_PROTO_DETAIL_IMPL_FILTER_HPP | ||
|
||
#include <boost/http_proto/detail/except.hpp> | ||
#include <boost/buffers/range.hpp> | ||
#include <boost/buffers/type_traits.hpp> | ||
#include <boost/core/ignore_unused.hpp> | ||
#include <boost/buffers/algorithm.hpp> | ||
|
||
namespace boost { | ||
namespace http_proto { | ||
namespace detail { | ||
|
||
template< | ||
class T, | ||
std::size_t N> | ||
class filter::unrolled | ||
class MutableBufferSequence, | ||
class ConstBufferSequence> | ||
auto | ||
filter:: | ||
process_impl( | ||
MutableBufferSequence const& out, | ||
ConstBufferSequence const& in, | ||
bool more) -> | ||
results | ||
{ | ||
using value_type = typename | ||
std::conditional< | ||
buffers::is_mutable_buffer_sequence<T>::value, | ||
buffers::mutable_buffer, | ||
buffers::const_buffer | ||
>::type; | ||
results rv; | ||
auto it_o = buffers::begin(out); | ||
auto it_i = buffers::begin(in); | ||
|
||
using span_type = typename | ||
std::conditional< | ||
buffers::is_mutable_buffer_sequence<T>::value, | ||
buffers::mutable_buffer_span, | ||
buffers::const_buffer_span | ||
>::type; | ||
if(it_o == buffers::end(out) || it_i == buffers::end(in)) | ||
return rv; | ||
|
||
using iter_type = decltype( | ||
begin(std::declval<T const&>())); | ||
auto ob = *it_o; | ||
auto ib = *it_i; | ||
for(;;) | ||
{ | ||
results rs = process_impl(ob, ib, more); | ||
|
||
using end_type = decltype( | ||
end(std::declval<T const&>())); | ||
rv.out_bytes += rs.out_bytes; | ||
rv.in_bytes += rs.in_bytes; | ||
rv.ec = rs.ec; | ||
rv.finished = rs.finished; | ||
|
||
value_type b_[N]; | ||
iter_type it_; | ||
end_type end_; | ||
std::size_t n_; | ||
if(rv.finished || rv.ec) | ||
return rv; | ||
|
||
public: | ||
explicit | ||
unrolled( | ||
T const& t) noexcept | ||
: it_(begin(t)) | ||
, end_(end(t)) | ||
{ | ||
} | ||
ob = buffers::sans_prefix(ob, rs.out_bytes); | ||
ib = buffers::sans_prefix(ib, rs.in_bytes); | ||
|
||
bool | ||
empty() const noexcept | ||
{ | ||
return n_ == 0; | ||
} | ||
if(ob.size() == 0) | ||
{ | ||
if(++it_o == buffers::end(out)) | ||
return rv; | ||
ob = *it_o; | ||
} | ||
|
||
span_type | ||
increment() | ||
{ | ||
n_ = 0; | ||
while(n_ < N) | ||
if(ib.size() == 0) | ||
{ | ||
if(it_ == end_) | ||
break; | ||
b_[n_++] = *it_++; | ||
if(++it_i == buffers::end(in)) | ||
return rv; | ||
ib = *it_i; | ||
} | ||
return span_type(&b_[0], n_); | ||
} | ||
}; | ||
|
||
template< | ||
class MutableBuffers, | ||
class ConstBuffers> | ||
auto | ||
filter:: | ||
process_impl( | ||
MutableBuffers const& out, | ||
ConstBuffers const& in, | ||
bool more) -> | ||
results | ||
{ | ||
boost::ignore_unused(more); | ||
results rv; | ||
constexpr int N = 16; | ||
unrolled<ConstBuffers, N> u0(in); | ||
unrolled<MutableBuffers, N> u1(out); | ||
|
||
return rv; | ||
} | ||
|
||
} // detail | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do Asio-style buffer sequences work when passed to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, except here we are using
buffers::begin
andbuffers::end
. By the way, the filter is an implementation detail, so a user-passed buffer sequence would never encounter it directly.