Subject: Re: [boost] [beast] Automatic content-length?
From: Vinnie Falco (vinnie.falco_at_[hidden])
Date: 2017-07-02 13:28:29


On Sun, Jul 2, 2017 at 6:21 AM, Peter Dimov via Boost
<boost_at_[hidden]> wrote:
> In this code, extracted from one of the examples in the documentation,
> ...
> res.body = "Invalid request-method '" + req.method_string().to_string() +
> "'";
> ...
> write(stream, res, ec);
> ...
> field::content_length isn't set.

Looks like you found a bug! One that I wrote, no less..

> Will Beast insert Content-Length based on the body size,
> or will it send the response with the field missing?

Beast will only set the content length if you ask it to, by calling
message::prepare_payload. The library does not perform any validation
on caller-provided HTTP inputs. For example if you called
msg.set("x:y", "z") that would result in a malformed message (colons
cannot appear in field names). Or if you set the content length
manually and lied about the correct value.

> The reason I ask is that I foresee forgetting the content_length to be a
> common mistake, and an asymptomatic one.

Well it wouldn't be asymptomatic in a real server since the other end
would hang, waiting for the "end of stream" to denote the end of the
HTTP message.

Thanks