Skip to content

Commit 6f2dfda

Browse files
committed
Address Copilot follow-up on transform cleanup and docs/tests.
Clarify transform-inactive test/docs wording, assert Content-Type in transform-active set-body cases, and document why transform cleanup remains guarded in the internal-body bypass path to avoid the known -11 crash. Made-with: Cursor
1 parent cf53d32 commit 6f2dfda

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

doc/admin-guide/plugins/header_rewrite.en.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,8 @@ set-body
11771177

11781178
set-body <text>
11791179

1180-
Sets the body to ``<text>``. Can also be used to delete a body with ``""``.
1180+
Sets the body to ``<text>``.
1181+
For internally generated/synthetic responses, ``set-body ""`` can be used to clear that replacement body.
11811182

11821183
For origin response replacement, ``set-body`` is supported at both
11831184
``READ_RESPONSE_HDR_HOOK`` and ``SEND_RESPONSE_HDR_HOOK``. Prefer
@@ -1192,9 +1193,9 @@ response body tunneling starts.
11921193
``set-body ""`` clears the internal replacement body, but does not suppress an
11931194
origin response body on this hook; use a non-empty replacement value when
11941195
sanitizing origin responses.
1195-
The gold tests cover origin replacement for both hooks with and without a
1196-
response transform plugin. The no-transform matrix runs with HTTP cache
1197-
disabled and includes repeated-URL cache-bypass probes.
1196+
The gold tests cover origin replacement for both hooks with and without an
1197+
active response transform. The transform-inactive matrix runs with HTTP cache
1198+
disabled and includes repeated-URL probes to verify deterministic replacement.
11981199

11991200
set-body-from
12001201
~~~~~~~~~~~~~

src/proxy/http/HttpSM.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7617,6 +7617,8 @@ HttpSM::setup_client_request_plugin_agents(HttpTunnelProducer *p, int num_header
76177617
inline void
76187618
HttpSM::transform_cleanup(TSHttpHookID hook, HttpTransformInfo *info)
76197619
{
7620+
// Internal-body bypass can skip transform tunnel setup, leaving no transform
7621+
// entry to clean up. In that case there is nothing safe/useful to close here.
76207622
if (info->entry == nullptr) {
76217623
return;
76227624
}
@@ -7712,6 +7714,9 @@ HttpSM::kill_this()
77127714
if (hooks_set) {
77137715
bool bypassed_response_transform =
77147716
t_state.api_info.cache_untransformed && t_state.internal_msg_buffer && !t_state.api_server_request_body_set;
7717+
// If we intentionally bypassed response transforms for internal-body
7718+
// transfer, transform_info may be partially detached; skip cleanup in this
7719+
// specific case to avoid dereferencing stale transform state.
77157720
if (!bypassed_response_transform) {
77167721
transform_cleanup(TS_HTTP_RESPONSE_TRANSFORM_HOOK, &transform_info);
77177722
}

tests/gold_tests/pluginTest/header_rewrite/header_rewrite_set_body_origin.replay.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ meta:
1818
version: "1.0"
1919

2020
autest:
21-
description: 'Test set-body origin replacement without response transforms'
21+
description: 'Test set-body origin replacement (transform plugin loaded; selected paths keep it inactive)'
2222

2323
dns:
2424
name: 'dns'
@@ -47,31 +47,31 @@ autest:
4747
proxy.config.diags.debug.tags: 'http|header_rewrite'
4848

4949
remap_config:
50-
# Block 1: READ_RESPONSE hook replacement path (no transform plugin).
50+
# Block 1: READ_RESPONSE hook replacement path with transform inactive (non-200 response).
5151
- from: "http://www.example.com/set_body_read_resp_403/"
5252
to: "http://backend.ex:{SERVER_HTTP_PORT}/origin_read_403/"
5353
plugins:
5454
- name: "header_rewrite.so"
5555
args:
5656
- "rules/rule_set_body_origin_read_resp.conf"
5757

58-
# Block 2: SEND_RESPONSE hook replacement path (no transform plugin).
58+
# Block 2: SEND_RESPONSE hook replacement path with transform inactive (non-200 response).
5959
- from: "http://www.example.com/set_body_send_resp_403/"
6060
to: "http://backend.ex:{SERVER_HTTP_PORT}/origin_send_403/"
6161
plugins:
6262
- name: "header_rewrite.so"
6363
args:
6464
- "rules/rule_set_body_origin_send_resp.conf"
6565

66-
# Block 3a: cache-bypass probe for READ_RESPONSE hook (same URL twice).
66+
# Block 3a: repeated-URL probe for READ_RESPONSE hook (same URL twice, transform inactive).
6767
- from: "http://www.example.com/cache_probe_read/"
6868
to: "http://backend.ex:{SERVER_HTTP_PORT}/cache_probe_read/"
6969
plugins:
7070
- name: "header_rewrite.so"
7171
args:
7272
- "rules/rule_set_body_origin_read_resp.conf"
7373

74-
# Block 3b: cache-bypass probe for SEND_RESPONSE hook (same URL twice).
74+
# Block 3b: repeated-URL probe for SEND_RESPONSE hook (same URL twice, transform inactive).
7575
- from: "http://www.example.com/cache_probe_send/"
7676
to: "http://backend.ex:{SERVER_HTTP_PORT}/cache_probe_send/"
7777
plugins:
@@ -160,7 +160,7 @@ sessions:
160160
size: 9
161161
data: "Sanitized"
162162

163-
# Block 3a verification: cache-bypass probe for READ_RESPONSE.
163+
# Block 3a verification: repeated-URL probe for READ_RESPONSE.
164164
# First response on repeated URL.
165165
- client-request:
166166
method: "GET"
@@ -191,7 +191,7 @@ sessions:
191191
size: 9
192192
data: "Sanitized"
193193

194-
# Block 3a verification: cache-bypass probe for READ_RESPONSE.
194+
# Block 3a verification: repeated-URL probe for READ_RESPONSE.
195195
# Second response on repeated URL should still be replaced.
196196
# Keep this as non-200 so null_transform does not engage.
197197
- client-request:
@@ -223,7 +223,7 @@ sessions:
223223
size: 9
224224
data: "Sanitized"
225225

226-
# Block 3b verification: cache-bypass probe for SEND_RESPONSE.
226+
# Block 3b verification: repeated-URL probe for SEND_RESPONSE.
227227
# First response on repeated URL.
228228
- client-request:
229229
method: "GET"
@@ -254,7 +254,7 @@ sessions:
254254
size: 9
255255
data: "Sanitized"
256256

257-
# Block 3b verification: cache-bypass probe for SEND_RESPONSE.
257+
# Block 3b verification: repeated-URL probe for SEND_RESPONSE.
258258
# Second response on repeated URL should still be replaced.
259259
# Keep this as non-200 so null_transform does not engage.
260260
- client-request:
@@ -312,6 +312,7 @@ sessions:
312312
headers:
313313
fields:
314314
- [ Content-Length, { value: "9", as: equal } ]
315+
- [ Content-Type, { value: "text/html", as: equal } ]
315316
content:
316317
size: 9
317318
data: "Sanitized"
@@ -342,6 +343,7 @@ sessions:
342343
headers:
343344
fields:
344345
- [ Content-Length, { value: "9", as: equal } ]
346+
- [ Content-Type, { value: "text/html", as: equal } ]
345347
content:
346348
size: 9
347349
data: "Sanitized"

0 commit comments

Comments
 (0)