Repository navigation
Normalize buffered localhost proxy responses - #18667
Conversation
AsyncClient removes chunk framing before delivering buffered responses, so normalize the response before redirect, Refresh, and Spark UI rewrites. This prevents decoded bodies from retaining a Transfer-Encoding: chunked label and being decoded again downstream.\n\nAdd regression coverage for redirect headers and Spark UI rewriting.\n\nCloses #18626.
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
| response.setHeader("Location", "/location-target"); | ||
| response.setHeader("Refresh", "/refresh-target"); | ||
| response.setHeader("Transfer-Encoding", "Chunked"); | ||
| response.setBody("decoded redirect body"); |
There was a problem hiding this comment.
This Content-Length assertion (line 100) can't fail, so it doesn't cover the normalization it's meant to.
Response::setBody(const std::string&) bottoms out in the templated setBody(istream&, ...), which ends with setContentLength(body_.length()) (core/http/Response.hpp:257). So this line already stamps Content-Length: 21 on the fixture, and Response::assign copies headers verbatim into preparedResponse. Delete pPreparedResponse->setContentLength(response.body().size()) from prepareLocalhostResponse and the test still passes.
A real chunked upstream response carries no Content-Length at all — that's the whole reason the normalization has to add one. Clearing it on the fixture makes the assertion discriminate:
| response.setBody("decoded redirect body"); | |
| response.setBody("decoded redirect body"); | |
| response.removeHeader("Content-Length"); |
(The same shape applies to the Spark UI test at line 135, though there rewriteSparkUIResponse's setBody legitimately owns the final value.)
| http::Response response; | ||
| response.setStatusCode(http::status::MovedTemporarily); | ||
| response.setHeader("Location", "/location-target"); | ||
| response.setHeader("Refresh", "/refresh-target"); |
There was a problem hiding this comment.
A bare path isn't a shape Refresh actually takes — real headers are Refresh: 0; url=/dashboard.
rewriteLocalhostAddressHeader only rewrites values that start with / or with the proxied absolute address; anything else falls through to replaceHeader unchanged. So the conventional form reaches the browser unrewritten and points at the server root instead of /p/<port>/dashboard, and this test wouldn't notice.
The rewrite limitation predates this PR, so it's not a bug introduced here — but the test as written reads like coverage of the Refresh path when the production shape isn't exercised. Worth either using "0; url=/refresh-target" (and asserting current behaviour) or noting the limitation in the test.
gtritchie
left a comment
There was a problem hiding this comment.
LGTM! Some very minor non-blocking findings posted.
Intent
Fix the deterministic protocol mismatch described in #18626.
AsyncClientconsumes chunk framing before returning a buffered localhost response, but redirect/Refresh and Spark UI branches could retain the upstreamTransfer-Encoding: chunkedheader and cause the decoded body to be decoded again downstream.Closes #18626.
Approach
Normalize a single copied response before any buffered-response rewrite:
Transfer-Encodingwhenchunkedis the final transfer codingContent-Lengthto the decoded body sizeWebSocket upgrades remain on their existing streaming path. This regression was introduced by the unreleased localhost streaming work in #18541, so no NEWS entry is needed.
Automated Tests
Added server unit tests covering:
Local validation:
cmake --build build --target rserver-tests -j 8./rserver-tests— 79 passed, 11 PostgreSQL tests skipped becausePOSTGRES_ENABLEDwas not setgit diff --checkQA Notes
The regression tests construct the post-
AsyncClientbuffered response directly and verify that redirect/Refresh and Spark UI branches emit a single valid framing signal. Optional manual QA can proxy an upstream endpoint that returns a chunked redirect and confirm the downstream response hasContent-LengthwithoutTransfer-Encoding.Documentation
None. This is an internal HTTP framing correction with no user-facing configuration or UI changes.
Checklist