boostorg / boostorg/beast

Beast header parsing doesn't consume as many octets as it can

Open
#2,737 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
4.8k
Forks
694
Avg merge
12h 48m
Merged PRs (30d)
1

Description

https://godbolt.org/z/cPd7h7n8G

In the above compiler explorer sample, we see that theoretically Beast can parse up to 30 octets but instead only parses 16 and then requests that the user update the buffer.

This works fine in most cases for Asio applications as buffers are entirely owned by the caller but does not work so well when using io_uring's multishot recv() method where buffers are owned by the ring so _not_ parsing as many octets as possible gums up the application.

Beast should parse as many octets as possible, fully consuming the buffer so long as the provided octets are valid.

Inlined example for posterity:
```cpp
#include
#include
#include
#include

#include
#include

namespace http = boost::beast::http;
namespace asio = boost::asio;

int main() {
char const* msg="GET / HTTP/1.1\r\nConnection: cl";

http::request_parser p;
boost::system::error_code ec;
auto n = p.put(asio::buffer(msg, std::strlen(msg)), ec);
if (n != std::strlen(msg)) {
std::cout << "only parsed: " << n << " octets.\n";
std::cout << "we should've parsed: " << std::strlen(msg) << " octets\n";
return 1;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.