Skip to content

http_serializer with buffer_body emits zero-sized chunk surprisingly, breaking HTTP framing #3032

@pgit

Description

@pgit

When finishing a chunked body like this:

message.body().data = <non-null-ptr>
message.body().size = 0;
message.body().more = false;

TWO zero-sized chunks are emitted, breaking HTTP framing. Only if data is actually set to nullptr, this works.

My usecase is serializing a sequence of std::string_view, using an empty one as EOM marker. An empty string view may have a non-null data pointer. Only if I do

message.body().data = sv.size() ? const_cast<void*>(sv.data()) : nullptr;
message.body().size = sv.size();
message.body().more = sv.size() != 0; // empty sv --> EOM

this becomes safe. One could argue that beast is so low-level that the caller has to know about this subtle difference, but as the 0-sized chunk has a very specific meaning in HTTP, IMO a safeguard against this could be warranted.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions