Skip to content

Commit 7b38a1f

Browse files
Add maxRemainingBodyLength() getter to HttpResponse (#1913)
* Initial plan * Add remainingBodyLength() getter to HttpParser and HttpResponse Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com> * Improve comments for remainingBodyLength() to cover all states Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com> * Rename remainingBodyLength to maxRemainingBodyLength * Rename remainingBodyLength to maxRemainingBodyLength --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com>
1 parent c7b37fc commit 7b38a1f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/HttpParser.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,14 @@ struct HttpParser {
615615
}
616616

617617
public:
618+
/* Returns the remaining body length if set via content-length, UINT64_MAX if transfer-encoding is chunked, or 0 if no body */
619+
uint64_t maxRemainingBodyLength() {
620+
if (isParsingChunkedEncoding(remainingStreamingBytes)) {
621+
return UINT64_MAX;
622+
}
623+
return remainingStreamingBytes;
624+
}
625+
618626
std::pair<unsigned int, void *> consumePostPadded(char *data, unsigned int length, void *user, void *reserved, MoveOnlyFunction<void *(void *, HttpRequest *)> &&requestHandler, MoveOnlyFunction<void *(void *, std::string_view, bool)> &&dataHandler) {
619627

620628
/* This resets BloomFilter by construction, but later we also reset it again.

src/HttpResponse.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,13 @@ struct HttpResponse : public AsyncSocket<SSL> {
488488
return httpResponseData->offset;
489489
}
490490

491+
/* Get the remaining body length if set via content-length, UINT64_MAX if transfer-encoding is chunked, or 0 if no body */
492+
uint64_t maxRemainingBodyLength() {
493+
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
494+
495+
return httpResponseData->maxRemainingBodyLength();
496+
}
497+
491498
/* If you are messing around with sendfile you might want to override the offset. */
492499
void overrideWriteOffset(uintmax_t offset) {
493500
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();

0 commit comments

Comments
 (0)