mirror of
https://github.com/alibaba/higress.git
synced 2026-04-20 11:37:27 +08:00
feat(transformer): Add split and retain strategy for dedupe (#2761)
This commit is contained in:
@@ -632,6 +632,38 @@ var WasmPluginsTransformer = suite.ConformanceTest{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case 18: request header transformer with split",
|
||||
TargetBackend: "infra-backend-v1",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo18.com",
|
||||
Path: "/get",
|
||||
RawHeaders: map[string][]string{
|
||||
"X-split-dedupe-first": {"1,2,3"},
|
||||
"X-split-dedupe-last": {"a,b,c"},
|
||||
},
|
||||
},
|
||||
ExpectedRequest: &http.ExpectedRequest{
|
||||
Request: http.Request{
|
||||
Host: "foo18.com",
|
||||
Path: "/get",
|
||||
Headers: map[string]string{
|
||||
"X-split-dedupe-first": "1",
|
||||
"X-split-dedupe-last": "c",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
t.Run("WasmPlugin transformer", func(t *testing.T) {
|
||||
for _, testcase := range testcases {
|
||||
|
||||
@@ -400,6 +400,26 @@ spec:
|
||||
port:
|
||||
number: 8080
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
name: wasmplugin-transform-request-header-split
|
||||
namespace: higress-conformance-infra
|
||||
spec:
|
||||
ingressClassName: higress
|
||||
rules:
|
||||
- host: "foo18.com"
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: infra-backend-v1
|
||||
port:
|
||||
number: 8080
|
||||
---
|
||||
apiVersion: extensions.higress.io/v1alpha1
|
||||
kind: WasmPlugin
|
||||
metadata:
|
||||
@@ -860,4 +880,15 @@ spec:
|
||||
headers:
|
||||
- key: reroute
|
||||
newValue: true
|
||||
- ingress:
|
||||
- higress-conformance-infra/wasmplugin-transform-request-header-split
|
||||
configDisable: false
|
||||
config:
|
||||
reqRules:
|
||||
- operate: dedupe
|
||||
headers:
|
||||
- key: X-split-dedupe-first
|
||||
strategy: SPLIT_AND_RETAIN_FIRST
|
||||
- key: X-split-dedupe-last
|
||||
strategy: SPLIT_AND_RETAIN_LAST
|
||||
url: file:///opt/plugins/wasm-go/extensions/transformer/plugin.wasm
|
||||
|
||||
@@ -93,6 +93,7 @@ type Request struct {
|
||||
Method string
|
||||
Path string
|
||||
Headers map[string]string
|
||||
RawHeaders http.Header
|
||||
Body []byte
|
||||
ContentType string
|
||||
UnfollowRedirect bool
|
||||
@@ -240,6 +241,14 @@ func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripp
|
||||
}
|
||||
}
|
||||
|
||||
if expected.Request.ActualRequest.RawHeaders != nil {
|
||||
for name, values := range expected.Request.ActualRequest.RawHeaders {
|
||||
for _, value := range values {
|
||||
req.Headers[name] = append(req.Headers[name], strings.TrimSpace(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
backendSetHeaders := make([]string, 0, len(expected.Response.AdditionalResponseHeaders))
|
||||
for name, val := range expected.Response.AdditionalResponseHeaders {
|
||||
backendSetHeaders = append(backendSetHeaders, name+":"+val)
|
||||
@@ -755,7 +764,7 @@ func (er *Assertion) GetTestCaseName(i int) string {
|
||||
headerStr := ""
|
||||
reqStr := ""
|
||||
|
||||
if er.Request.ActualRequest.Headers != nil {
|
||||
if er.Request.ActualRequest.Headers != nil || er.Request.ActualRequest.RawHeaders != nil {
|
||||
headerStr = " with headers"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user