Skip to content

Normalize buffered localhost proxy responses - #18667

Merged
kevinushey merged 1 commit into
mainfrom
codex/18626-normalize-localhost-proxy-response
Aug 30, 2026
Merged

kevinushey merged 1 commit into
mainfrom
codex/18626-normalize-localhost-proxy-response

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Fix the deterministic protocol mismatch described in #18626. AsyncClient consumes chunk framing before returning a buffered localhost response, but redirect/Refresh and Spark UI branches could retain the upstream Transfer-Encoding: chunked header and cause the decoded body to be decoded again downstream.

Closes #18626.

Approach

Normalize a single copied response before any buffered-response rewrite:

  • remove Transfer-Encoding when chunked is the final transfer coding
  • set Content-Length to the decoded body size
  • apply Location, Refresh, and Spark UI rewrites to that normalized response
  • send the same prepared response through the ordinary buffered path

WebSocket 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:

  • chunked responses with both Location and Refresh headers
  • chunked Spark UI responses whose body is rewritten

Local validation:

  • cmake --build build --target rserver-tests -j 8
  • ./rserver-tests — 79 passed, 11 PostgreSQL tests skipped because POSTGRES_ENABLED was not set
  • git diff --check

QA Notes

The regression tests construct the post-AsyncClient buffered 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 has Content-Length without Transfer-Encoding.

Documentation

None. This is an internal HTTP framing correction with no user-facing configuration or UI changes.

Checklist

  • NEWS is not required because this fixes an unreleased regression
  • No UI or accessibility changes
  • A reviewer is assigned to this PR
  • This PR passes all runnable local unit tests

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.
@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
2422 0 161 0
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 603 0 31 0
✅ desktop-macos 600 0 35 0
✅ desktop-windows 609 0 31 0
✅ server-linux 582 0 44 0
✅ setup 26 0 10 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit d39e03f182ce035242b23a2399ed7986c914677f - Run #732

@gtritchie gtritchie added this to the 2026.09 (Autumn Hawkbit) milestone Aug 29, 2026
response.setHeader("Location", "/location-target");
response.setHeader("Refresh", "/refresh-target");
response.setHeader("Transfer-Encoding", "Chunked");
response.setBody("decoded redirect body");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Some very minor non-blocking findings posted.

@kevinushey
kevinushey merged commit 65b0fc0 into main Aug 30, 2026
29 checks passed
@kevinushey
kevinushey deleted the codex/18626-normalize-localhost-proxy-response branch August 30, 2026 22:43
@gtritchie gtritchie mentioned this pull request Aug 31, 2026
3 of 4 tasks

This branch was previously deployed

1 inactive deployment
e2e-playwright — d39e03f1 Deployed Aug 28, 2026 by kevinushey via windows / e2e-desktop-windows (6) #732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Normalize de-chunked localhost proxy responses before rewriting them

2 participants