Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Beast includes CRLF in HTTP fields
From: Vinnie Falco (vinnie.falco_at_[hidden])
Date: 2018-07-06 15:31:52


On Fri, Jul 6, 2018 at 3:45 AM, David Demelier via Boost-users
<boost-users_at_[hidden]> wrote:
> It looks like HTTP response headers are saved with trailing CRLF in the
> message upon receiption after (async_)read.

Yes, beast::http::basic_fields stores each field/value pair in its
serialized format, which includes the trailing CRLF and also the colon
and space. It is done this way so that beast::http::serializer
requires no memory allocations to perform its function.

> Since it usually does not add additional valuable information, would it
> be possible to remove them in next version of Boost.Beast?

No

> It will be more convenient as you don't need to trim them when you want
> to capture the field value.

You shouldn't have to do any trimming. basic_fields member functions
and iterator value_type which return field values do so using a
string_view, whose length excludes the trailing CRLF and also any
colon and space. Callers should not assume the string is
null-terminated, and work with the interface provided by string_view.

See:

<https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/ref/boost__beast__http__basic_fields__value_type/name_string.html>
<https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/ref/boost__beast__http__basic_fields__value_type/value.html>
<https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/ref/boost__beast__http__basic_fields/operator_lb__rb_/overload1.html>

Thanks


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net