fix: avoid waiting for missing request bodies in transformer (#4024)

Signed-off-by: johnlanni <zty98751@alibaba-inc.com>
This commit is contained in:
澄潭
2026-06-25 17:36:01 +08:00
committed by GitHub
parent 39ec41aab6
commit 6c98ea74e0
2 changed files with 43 additions and 4 deletions

View File

@@ -424,6 +424,43 @@ func TestRequest_MapFromBody_DelaysHeaderTransform(t *testing.T) {
})
}
func TestRequest_MapFromBody_NoRequestBodyDoesNotPause(t *testing.T) {
test.RunTest(t, func(t *testing.T) {
host, status := test.NewTestHost(configJSON(map[string]any{
"reqRules": []map[string]any{
{
"operate": "map",
"mapSource": "body",
"headers": []map[string]any{
{"fromKey": "user.id", "toKey": "X-User-Id"},
},
},
{
"operate": "add",
"headers": []map[string]any{
{"key": "X-Static", "value": "ok"},
},
},
},
}))
defer host.Reset()
require.Equal(t, types.OnPluginStartStatusOK, status)
action := host.CallOnHttpRequestHeaders([][2]string{
{":authority", "test.com"},
{":path", "/p"},
{":method", "POST"},
{"content-type", "application/json"},
}, test.WithEndOfStream(true))
require.Equal(t, types.ActionContinue, action, "request without body must not wait for body callback")
got := headersToMap(host.GetRequestHeaders())
require.Equal(t, []string{"ok"}, got["x-static"])
require.NotContains(t, got, "x-user-id")
host.CompleteHttp()
})
}
// --- regex template ---
func TestRequest_Headers_AddWithHostPattern(t *testing.T) {