1  
//
1  
//
2  
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
3  
// Copyright (c) 2024 Mohammad Nejati
3  
// Copyright (c) 2024 Mohammad Nejati
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/cppalliance/http
8  
// Official repository: https://github.com/cppalliance/http
9  
//
9  
//
10  

10  

11  
#include "src/detail/filter.hpp"
11  
#include "src/detail/filter.hpp"
12  

12  

13  
#include <boost/capy/buffers/front.hpp>
13  
#include <boost/capy/buffers/front.hpp>
14  

14  

15  
namespace boost {
15  
namespace boost {
16  
namespace http {
16  
namespace http {
17  
namespace detail {
17  
namespace detail {
18  

18  

19  
auto
19  
auto
20  
filter::
20  
filter::
21  
process(
21  
process(
22  
    capy::slice_of<
22  
    capy::slice_of<
23  
        boost::span<const capy::mutable_buffer>> out,
23  
        boost::span<const capy::mutable_buffer>> out,
24  
    capy::const_buffer_pair in,
24  
    capy::const_buffer_pair in,
25  
    bool more) -> results
25  
    bool more) -> results
26  
{
26  
{
27  
    results rv;
27  
    results rv;
28  
    bool p_more = true;
28  
    bool p_more = true;
29  
    for(;;)
29  
    for(;;)
30  
    {
30  
    {
31  
        if(!more && p_more && in[1].size() == 0)
31  
        if(!more && p_more && in[1].size() == 0)
32  
        {
32  
        {
33  
            if(capy::buffer_size(out) < min_out_buffer())
33  
            if(capy::buffer_size(out) < min_out_buffer())
34  
            {
34  
            {
35  
                rv.out_short = true;
35  
                rv.out_short = true;
36  
                return rv;
36  
                return rv;
37  
            }
37  
            }
38  
            p_more = false;
38  
            p_more = false;
39  
        }
39  
        }
40  

40  

41  
        auto ob = capy::front(out);
41  
        auto ob = capy::front(out);
42  
        auto ib = capy::front(in);
42  
        auto ib = capy::front(in);
43  
        auto rs = do_process(ob, ib, p_more);
43  
        auto rs = do_process(ob, ib, p_more);
44  

44  

45  
        rv.in_bytes  += rs.in_bytes;
45  
        rv.in_bytes  += rs.in_bytes;
46  
        rv.out_bytes += rs.out_bytes;
46  
        rv.out_bytes += rs.out_bytes;
47  

47  

48  
        if(rs.ec)
48  
        if(rs.ec)
49  
        {
49  
        {
50  
            rv.ec = rs.ec;
50  
            rv.ec = rs.ec;
51  
            return rv;
51  
            return rv;
52  
        }
52  
        }
53  

53  

54  
        if(rs.finished)
54  
        if(rs.finished)
55  
        {
55  
        {
56  
            rv.finished = true;
56  
            rv.finished = true;
57  
            return rv;
57  
            return rv;
58  
        }
58  
        }
59  

59  

60  
        capy::remove_prefix(out, rs.out_bytes);
60  
        capy::remove_prefix(out, rs.out_bytes);
61  
        capy::remove_prefix(in, rs.in_bytes);
61  
        capy::remove_prefix(in, rs.in_bytes);
62  

62  

63  
        if(capy::buffer_empty(out))
63  
        if(capy::buffer_empty(out))
64  
            return rv;
64  
            return rv;
65  

65  

66  
        if(capy::buffer_empty(in) && rs.out_bytes < ob.size())
66  
        if(capy::buffer_empty(in) && rs.out_bytes < ob.size())
67  
            return rv;
67  
            return rv;
68  
    }
68  
    }
69  
}
69  
}
70  

70  

71  
} // detail
71  
} // detail
72  
} // http
72  
} // http
73  
} // boost
73  
} // boost