Skip to content

Commit e6c17a3

Browse files
committed
Add option to ignore whitespace in the resposnse header values
Signed-off-by: Huabing (Robin) Zhao <[email protected]>
1 parent 33ed80c commit e6c17a3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

conformance/tests/httproute-cors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var HTTPRouteCORS = suite.ConformanceTest{
8484
"access-control-max-age": "3600",
8585
"access-control-allow-credentials": "true",
8686
},
87+
IgnoreWhitespace: true,
8788
},
8889
},
8990
{
@@ -120,6 +121,7 @@ var HTTPRouteCORS = suite.ConformanceTest{
120121
"access-control-max-age": "3600",
121122
"access-control-allow-credentials": "true",
122123
},
124+
IgnoreWhitespace: true,
123125
},
124126
},
125127
{

conformance/utils/http/http.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ type ExpectedRequest struct {
8383

8484
// Response defines expected properties of a response from a backend.
8585
type Response struct {
86-
StatusCode int
87-
Headers map[string]string
88-
AbsentHeaders []string
86+
StatusCode int
87+
Headers map[string]string
88+
AbsentHeaders []string
89+
IgnoreWhitespace bool
8990
}
9091

9192
type BackendRef struct {
@@ -314,8 +315,14 @@ func CompareRequest(t *testing.T, req *roundtripper.Request, cReq *roundtripper.
314315
actualVal, ok := cRes.Headers[strings.ToLower(name)]
315316
if !ok {
316317
return fmt.Errorf("expected %s header to be set, actual headers: %v", name, cRes.Headers)
317-
} else if strings.Join(actualVal, ",") != expectedVal {
318-
return fmt.Errorf("expected %s header to be set to %s, got %s", name, expectedVal, strings.Join(actualVal, ","))
318+
}
319+
actualValStr := strings.Join(actualVal, ",")
320+
if expected.Response.IgnoreWhitespace {
321+
actualValStr = strings.ReplaceAll(actualValStr, " ", "")
322+
expectedVal = strings.ReplaceAll(expectedVal, " ", "")
323+
}
324+
if actualValStr != expectedVal {
325+
return fmt.Errorf("expected %s header to be set to %s, got %s", name, expectedVal, actualValStr)
319326
}
320327
}
321328
}

0 commit comments

Comments
 (0)