feat(wasm-go): add field reroute to disable route reselection (#2739)

This commit is contained in:
WeixinX
2025-08-11 09:37:35 +08:00
committed by GitHub
parent a1bf1ff009
commit 33ce18df5a
7 changed files with 312 additions and 54 deletions

View File

@@ -575,6 +575,63 @@ var WasmPluginsTransformer = suite.ConformanceTest{
},
},
},
{
Meta: http.AssertionMeta{
TestCaseName: "case 16: request reroute",
TargetBackend: "infra-backend-v1",
TargetNamespace: "higress-conformance-infra",
},
Request: http.AssertionRequest{
ActualRequest: http.Request{
Host: "foo16.com",
Path: "/get",
Headers: map[string]string{
"reroute": "false",
},
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Host: "foo16.reroute.com",
Path: "/get",
Headers: map[string]string{"reroute": "true"},
},
},
},
Response: http.AssertionResponse{
ExpectedResponse: http.Response{
StatusCode: 200,
},
},
},
{
Meta: http.AssertionMeta{
TestCaseName: "case 17: request non reroute",
TargetBackend: "infra-backend-v1",
TargetNamespace: "higress-conformance-infra",
},
Request: http.AssertionRequest{
ActualRequest: http.Request{
Host: "foo17.com",
Path: "/get",
Headers: map[string]string{
"reroute": "false",
},
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Host: "foo17.non-reroute.com",
Path: "/get",
// although the header was replaced, it was not rerouted
Headers: map[string]string{"reroute": "true"},
},
},
},
Response: http.AssertionResponse{
ExpectedResponse: http.Response{
StatusCode: 200,
},
},
},
}
t.Run("WasmPlugin transformer", func(t *testing.T) {
for _, testcase := range testcases {

View File

@@ -312,6 +312,94 @@ spec:
port:
number: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wasmplugin-transform-request-reroute-root
namespace: higress-conformance-infra
annotations:
higress.io/exact-match-header-reroute: "false"
higress.io/upstream-vhost: "foo16.non-reroute.com"
spec:
ingressClassName: higress
rules:
- host: "foo16.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: infra-backend-v1
port:
number: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wasmplugin-transform-request-reroute
namespace: higress-conformance-infra
annotations:
higress.io/exact-match-header-reroute: "true"
higress.io/upstream-vhost: "foo16.reroute.com"
spec:
ingressClassName: higress
rules:
- host: "foo16.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: infra-backend-v1
port:
number: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wasmplugin-transform-request-non-reroute-root
namespace: higress-conformance-infra
annotations:
higress.io/exact-match-header-reroute: "false"
higress.io/upstream-vhost: "foo17.non-reroute.com"
spec:
ingressClassName: higress
rules:
- host: "foo17.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: infra-backend-v1
port:
number: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wasmplugin-transform-request-non-reroute
namespace: higress-conformance-infra
annotations:
higress.io/exact-match-header-reroute: "true"
higress.io/upstream-vhost: "foo17.reroute.com"
spec:
ingressClassName: higress
rules:
- host: "foo17.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: infra-backend-v1
port:
number: 8080
---
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
@@ -751,4 +839,25 @@ spec:
body:
- key: X-replace-body
newValue: exist-body
- ingress:
- higress-conformance-infra/wasmplugin-transform-request-reroute-root
configDisable: false
config:
reqRules:
- operate: replace
headers:
- key: reroute
newValue: true
- ingress:
- higress-conformance-infra/wasmplugin-transform-request-non-reroute-root
configDisable: false
config:
reroute: false
reqRules:
- operate: replace
headers:
- key: reroute
newValue: true
url: file:///opt/plugins/wasm-go/extensions/transformer/plugin.wasm