Skip to content

Commit 2975eee

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

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

conformance/tests/httproute-cors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ var HTTPRouteCORS = suite.ConformanceTest{
8484
"access-control-max-age": "3600",
8585
"access-control-allow-credentials": "true",
8686
},
87+
// Ignore whitespace when comparing the response headers. This is because some
88+
// implementations add a space after each comma, and some don't. Both are valid.
89+
IgnoreWhitespace: true,
8790
},
8891
},
8992
{
@@ -120,6 +123,9 @@ var HTTPRouteCORS = suite.ConformanceTest{
120123
"access-control-max-age": "3600",
121124
"access-control-allow-credentials": "true",
122125
},
126+
// Ignore whitespace when comparing the response headers. This is because some
127+
// implementations add a space after each comma, and some don't. Both are valid.
128+
IgnoreWhitespace: true,
123129
},
124130
},
125131
{

conformance/utils/http/http.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ type Response struct {
9898
Headers map[string]string
9999
AbsentHeaders []string
100100
Protocol string
101+
// IgnoreWhitespace will cause whitespace to be ignored when comparing the respond
102+
// header values.
103+
IgnoreWhitespace bool
101104
}
102105

103106
type BackendRef struct {
@@ -375,8 +378,14 @@ func CompareRoundTrip(t *testing.T, req *roundtripper.Request, cReq *roundtrippe
375378
actualVal, ok := cRes.Headers[strings.ToLower(name)]
376379
if !ok {
377380
return fmt.Errorf("expected %s header to be set, actual headers: %v", name, cRes.Headers)
378-
} else if strings.Join(actualVal, ",") != expectedVal {
379-
return fmt.Errorf("expected %s header to be set to %s, got %s", name, expectedVal, strings.Join(actualVal, ","))
381+
}
382+
actualValStr := strings.Join(actualVal, ",")
383+
if expected.Response.IgnoreWhitespace {
384+
actualValStr = strings.ReplaceAll(actualValStr, " ", "")
385+
expectedVal = strings.ReplaceAll(expectedVal, " ", "")
386+
}
387+
if actualValStr != expectedVal {
388+
return fmt.Errorf("expected %s header to be set to %s, got %s", name, expectedVal, actualValStr)
380389
}
381390
}
382391
}

0 commit comments

Comments
 (0)