4

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.

2
  • In C++ what you refer to is move-semantics, not inheritance. Commented Aug 5 at 15:38
  • @sehe Agree with you Commented Aug 6 at 10:07

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.