I am trying to implement a custom body type that would hold a parsed JSON tree object. The task seems pretty natural, but I can't find a way to generate non-chunked HTTP messages carrying JSON using Beast. I have a REST client/server implemented by wrapping libmicrohttpd and libcurl, but I would prefer moving to Boost Beast instead.
The problem, as I understand it, is that the body type's size(value_type const&)
method receives a reference to a body value to be serialized (a JSON tree object in my case), but there is no way to determine the exact length of a stringified JSON without actually stringifying that. However, if I remove the size()
method, Beast thinks that I am asking for the chunked transfer encoding. Of course, there is nothing wrong with the chunked encoding per se, but for me, it could mean fixing some automation and monitoring scripts, let alone the integration tests.
What I would like to do is to assign a JSON object to the message I am preparing, and then Beast to ask the writer, not body::size()
for the payload size. This seems logical to me, as the actual HTTP message body (serialized JSON) is quite different from a live JSON object in memory, and it is the body::writer who produces the body bytes for transferring. Am I wrong?
Anyway, do you think there is a nice way to solve this problem?
Thank you in advance for your time and effort!
Regards, Vlad