Skip to content

[WIP] http: Do not continue headers injected without end_stream as the end of the stream - #49409

Draft
phlax wants to merge 1 commit into
envoyproxy:mainfrom
phlax:http-inject-headers-end-stream
Draft

phlax wants to merge 1 commit into
envoyproxy:mainfrom
phlax:http-inject-headers-end-stream

Conversation

@phlax

@phlax phlax commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

injectDecodedHeadersToFilterChain() and injectEncodedHeadersToFilterChain()
(#47475) send the headers on with the end_stream the filter gives them, so a
filter can add a body to a header-only request or response: it injects the
headers without end_stream, and the body later.

A later filter that stops those headers continues them with the end of stream
the filter manager has observed (commonContinue()), which for a header-only
message is "ended". If it continued before the body was injected, it passed
the headers on as the end of the stream, and the body followed a stream the
rest of the chain had seen complete.

The filter manager now records that the headers were injected without
end_stream, and a filter that stopped them does not continue them as the
end of the stream. Only that: the observed end of stream is not changed, so
data that was buffered, and trailers, end the stream as they did (a filter
that buffers the whole body, injects the headers and then continues still
sends the body with end_stream).

Nothing in the tree is affected today: the one caller (ext_proc, in streamed
modes) does not inject the headers of a message without a body.

Risk Level: Low
Testing: Unit tests for the request and the response paths: a later filter continuing the injected headers of a header-only message (without the change both fail: Expected arg #1: is equal to false, Actual: true on the last filter's headers), and a buffered body continued after the headers are injected. With the change, //test/common/http/... and //test/extensions/filters/http/ext_proc/... pass.
Docs Changes: N/A
Release Notes: Added
Runtime guard: envoy.reloadable_features.http_inject_headers_without_end_stream

Found from the review of the backports of #47475 (#49404, #49405, #49406), which have the same code.

@phlax

phlax commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

cc @jwendell this is the follow up from your backports

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical issue clears the buffered final body's end-of-stream state when stopped headers are injected, leaving both decoder and encoder chains incomplete and requiring a fix with regression tests.

1 open issue
What changed in this PR

Updates Envoy’s HTTP filter manager to preserve injected headers’ end-of-stream state when a later filter pauses and resumes them, allowing an added body to follow.

Changes:

  • Records injected-header state on request and response paths under the existing runtime guard.
  • Adds regression tests for continuation before body injection.
  • Documents the fix and runtime rollback option.
File Description
test/​common/​http/​conn_manager_impl_test_3.cc Adds request and response continuation regression tests.
source/​common/​http/​filter_manager.cc Updates observed end-of-stream state during header injection.
changelogs/​current/​bug_fixes/​http__inject-headers-end-stream.rst Describes the fix and rollback guard.

Review effort: Balanced

Comment thread source/common/http/filter_manager.cc Resolved
@phlax
phlax marked this pull request as draft November 18, 2026 19:39
@phlax phlax changed the title http: Record the end of stream that injected headers say [WIP] http: Record the end of stream that injected headers say Nov 18, 2026
…of the stream

`injectDecodedHeadersToFilterChain()` and `injectEncodedHeadersToFilterChain()`
(envoyproxy#47475) send the headers on with the `end_stream` the filter gives them, so a
filter can add a body to a header-only request or response: it injects the
headers without `end_stream`, and the body later.

A later filter that stops those headers continues them with the end of stream
the filter manager has observed (`commonContinue()`), which for a header-only
message is "ended". If it continued before the body was injected, it passed
the headers on as the end of the stream, and the body followed a stream the
rest of the chain had seen complete.

The filter manager now records that the headers were injected without
`end_stream`, and a filter that stopped them does not continue them as the
end of the stream. Only that: the observed end of stream is not changed, so
data that was buffered, and trailers, end the stream as they did (a filter
that buffers the whole body, injects the headers and then continues still
sends the body with `end_stream`).

Nothing in the tree is affected today: the one caller (ext_proc, in streamed
modes) does not inject the headers of a message without a body.

Risk Level: Low
Testing: Unit tests for the request and the response paths: a later filter continuing the injected headers of a header-only message (fails without the change), and a buffered body continued after the headers are injected
Docs Changes: N/A
Release Notes: Added
Runtime guard: envoy.reloadable_features.http_inject_headers_without_end_stream

Signed-off-by: Ryan Northey <ryan@synca.io>
@phlax
phlax force-pushed the http-inject-headers-end-stream branch from 75148d5 to 6496068 Compare November 18, 2026 19:50
@phlax phlax changed the title [WIP] http: Record the end of stream that injected headers say [WIP] http: Do not continue headers injected without end_stream as the end of the stream Nov 18, 2026
@phlax
phlax requested a balanced review from Copilot November 18, 2026 19:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Mixed header injections can leave a stale flag that forwards terminal headers with end_stream=false and stalls decoding or encoding, and disabled-guard coverage is missing.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment on lines +528 to +532
if (!end_stream &&
Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.http_inject_headers_without_end_stream")) {
parent_.state().decode_headers_injected_without_end_stream_ = true;
}
// Filter adds a body to a header-only request: it injects the headers without end_stream, and the
// next filter stops them, and continues before the body is injected. The headers it continues
// with are not the end of the stream.
TEST_F(HttpConnectionManagerImplTest, FilterStopIterationInjectHeadersLaterFilterContinues) {

This branch has not been deployed

No deployments
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.

2 participants