Fix POST/PUT request bodies being lost server-side#10
Open
sclaiborne wants to merge 6 commits into
Open
Conversation
LLHttpParse only set contentPresent/partialContent in the HTTP response parsing branch. The request parsing branch never set them, so LLHttpServer dispatched POST/PUT requests with an empty body even though header.contentLength was correct. Also fix the partial-content accumulation in LLHttpServer: the parser was given the receive buffer base pointer but only the length of the latest TCP segment, so requests whose headers and body arrive in separate segments (e.g. from .NET HttpClient) never parsed completely. The null terminator was also being appended one byte past the received data, and the receive pointer shift now matches the accumulated length semantics. Reserve one byte of the receive buffer for the terminator. Repair the CMake test build after the src/Ar restructure (library include dirs, example subdirectory path, stale relative includes) and add tests covering request bodies and a POSTed JSON body split across two TCP segments. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
TMP_alloc memory is not initialized, so the internal client state (TCP stream state, FUB statuses, receive lengths) started as garbage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ection manager Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LLHttpParse()only setscontentPresent/partialContentin the HTTP response parsing branch. The request parsing branch never sets them, soLLHttpServer''s dispatch (if(client->parser.contentPresent)) always copied an empty body intoLLHttpResponsehandlers. POST/PUT bodies were silently lost server-side:requestLengthreported the Content-Length, butpRequestreceived only'\0'. Reproduced against ARsim withLLHttpServer+LLHttpResponse.On top of that, the partial-content accumulation path in
HttpServer.cwas broken for multi-segment requests: afterHttpShiftReceivePointer(), the parser was given the receive buffer base pointer but only the latest segment''sReceivedDataLength, so a request whose headers and body arrive in separate TCP segments (which is what .NETHttpClientsends - headers and body in separate writes) never parsed completely. The appended null terminator was also written one byte past the received data.Fix
HttpParse.c: mirror the response-branch logic at the end of the request branch - ifheader.contentLength != 0, setcontentPresent = 1andpartialContent = (returnValue + contentLength > dataLength).HttpServer.c:recvLength= shift offset + newly received length (matching the client''s accumulation inHttpClient.c), and shift the receive pointer by the new segment length only.data[recvLength]instead ofdata[recvLength+1], and reserve one byte of the receive buffer for it (as the client does).TMP_alloc''d client array inLLHttpServerInit()-TMP_allocmemory is not initialized, so TCP stream state/FUB statuses started as garbage.Tests
Added under
test/:contentPresent/content, request with partial body setspartialContent.Test-infra repairs (needed to build/run the suite at all)
CMakeLists.txt: thesrc/Arrestructure broke the CMake build -add_subdirectory(example)pointed at a directory with no CMakeLists, and the library target had no include dirs. Fixed paths and stale../LLHttpH.h-style includes intests.cpp/example.cpp.v3.0.0-preview3->v3.4.0(preview3 does not compile with current GCC) and renamedContains->ContainsSubstringper Catch2 v3 API.brsstrlenfallback macro for non-AR builds (used by the chunked-encoding path).report/directory at configure time soctestpasses on a clean checkout.Verified per
TestJenkinsfile: CMake + MinGW (32-bit, matching UDINT pointer width) build, full Catch2 suite green viactest- 7/7 test cases, 139 assertions.🤖 Generated with Claude Code