Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does http::response_parser inherits limits from source parser?

I create http::response_parser<http::buffer_body> and set header_limit and body_limit like this

auto parser = std::make_shared<http::response_parser<http::buffer_body>>();
parser->header_limit(std::numeric_limits<std::uint32_t>::max());
parser->body_limit(std::numeric_limits<std::uint64_t>::max());

Next, I transform the http::response_parser<http::buffer_body> parser into a parser of type http::response_parser<http::string_body> as follows

auto new_parser = std::make_shared<http::response_parser<http::string_body>>(std::move(*parser));

My question is, will new_parser inherit header_limit and body_limit from the original parser or not? I didn't find any methods that could report the current values of the given limits.

like image 651
Joe J Avatar asked Oct 24 '25 14:10

Joe J


1 Answers

Yes. The limits are part of basic_parser<> which defines only defaulted move and assignment.

It's also possible to test, using the friend-ness of basic_parser_test:

Live On Coliru

#include <boost/beast.hpp>

namespace boost::beast::http {
    class basic_parser_test {
      public:
        static void foo() {
            auto parser = std::make_shared<http::response_parser<http::buffer_body>>();
            parser->header_limit(std::numeric_limits<std::uint32_t>::max());
            parser->body_limit(std::numeric_limits<std::uint64_t>::max());

            auto new_parser = std::make_shared<http::response_parser<http::string_body>>(std::move(*parser));

            assert(new_parser->body_limit_ == std::numeric_limits<std::uint64_t>::max());
            assert(new_parser->header_limit_ == std::numeric_limits<std::uint32_t>::max());
        }
    };
} // namespace boost::beast::http

int main() {
    boost::beast::http::basic_parser_test::foo();
}

All asserts pass.

like image 90
sehe Avatar answered Oct 26 '25 04:10

sehe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!