35 const std::string body{req.
ReadBody()};
36 const auto transfer_encoding{req.
GetHeader(
"Transfer-Encoding")};
37 const auto content_length{req.
GetHeader(
"Content-Length")};
38 if (transfer_encoding &&
ToLower(*transfer_encoding) ==
"chunked") {
40 }
else if (content_length) {
41 const auto parsed_length{ToIntegral<uint64_t>(*content_length)};
43 assert(body.size() == *parsed_length);
60 }
catch (
const std::runtime_error&) {
66 (void)http_request.
GetURI();
72 CheckBodyMatchesFraming(http_request);
100 bool operator==(
const ParsedRequest&)
const =
default;
104 std::vector<ParsedRequest> requests;
106 std::string remainder;
112void Drain(
const std::shared_ptr<FuzzClient>&
client, RunResult&
out)
118 const size_t buffered{
client->GetRecvBuffer().size()};
131 assert(StateRank(cur->GetState()) >= StateRank(
out.last_state));
132 out.last_state = cur->GetState();
134 if (
const auto chunk_size{cur->GetChunkSize()}) {
135 assert(cur->GetChunkProgress() <= *chunk_size);
143 CheckBodyMatchesFraming(*req);
148 const size_t buffered{
client->GetRecvBuffer().size()};
172 auto client{std::make_shared<FuzzClient>()};
175 one_shot.remainder =
client->GetRecvBuffer();
182 auto client{std::make_shared<FuzzClient>()};
183 std::string_view remaining{input};
184 while (!remaining.empty()) {
186 client->Receive(remaining.substr(0, n));
187 remaining = remaining.substr(n);
190 sliced.remainder =
client->GetRecvBuffer();
193 assert(one_shot.requests == sliced.requests);
194 assert(one_shot.errored == sliced.errored);
197 if (!one_shot.errored)
assert(one_shot.remainder == sliced.remainder);
#define Assert(val)
Identity function.
A combination of a network address (CNetAddr) and a (TCP) port.
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Helper to initialize the global MockableSteadyClock, let a duration elapse, and reset it after use in...
std::string ConsumeRandomLengthString(size_t max_length)
T ConsumeIntegralInRange(T min, T max)
std::string & MutateRecvBuffer()
Used for tests.
static std::unique_ptr< HTTPRequest > TryReadRequest(const std::shared_ptr< HTTPRemoteClient > &client) EXCLUSIVE_LOCKS_REQUIRED(!client -> m_send_mutex)
Try to read an HTTPRequest from a client's receive buffer.
void Receive() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex)
void WriteHeader(std::string &&hdr, std::string &&value)
std::string GetURI() const
bool LoadHeaders(util::LineReader &reader)
bool LoadControlData(util::LineReader &reader)
Methods that attempt to parse HTTP request fields line-by-line from a receive buffer.
std::optional< std::string > GetHeader(std::string_view hdr) const
HTTPRequestMethod GetRequestMethod() const
std::string ReadBody() const
bool LoadBody(util::LineReader &reader)
void WriteReply(HTTPStatusCode status, std::span< const std::byte > reply_body={})
A mocked Sock alternative that succeeds on all operations.
std::string_view RequestMethodString(HTTPRequestMethod m)
HTTP request method as string - use for logging only.
FUZZ_TARGET(http_request)
std::unique_ptr< ProxyClient< messages::FooInterface > > client
constexpr uint64_t MAX_BODY_SIZE
Maximum size of an HTTP request body received from a client.
constexpr size_t MAX_HEADERS_SIZE
Maximum size of each headers line in an HTTP request, also the maximum size of all headers total.
bool operator==(const CNetAddr &a, const CNetAddr &b)
FuzzedDataProvider provider
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
FuzzedDataProvider & fuzzed_data_provider