Skip to content

Commit 4447aeb

Browse files
committed
refactor: refactor request handling and improve CORS checks
- Refactor `performRequestWithHeaders` function signature for better readability - Standardize the string comparison order in CORS origin checks Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 9d49f16 commit 4447aeb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cors_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ func performRequest(r http.Handler, method, origin string) *httptest.ResponseRec
5454
return performRequestWithHeaders(r, method, "/", origin, http.Header{})
5555
}
5656

57-
func performRequestWithHeaders(r http.Handler, method, path, origin string, header http.Header) *httptest.ResponseRecorder {
57+
func performRequestWithHeaders(
58+
r http.Handler,
59+
method, path, origin string,
60+
header http.Header,
61+
) *httptest.ResponseRecorder {
5862
req, _ := http.NewRequestWithContext(context.Background(), method, path, nil)
5963
// From go/net/http/request.go:
6064
// For incoming requests, the Host header is promoted to the
@@ -472,11 +476,11 @@ func TestMultiGroupRouter(t *testing.T) {
472476
AllowOriginWithContextFunc: func(c *gin.Context, origin string) bool {
473477
path := c.Request.URL.Path
474478
if strings.HasPrefix(path, "/app1") {
475-
return "http://app1.example.com" == origin
479+
return origin == "http://app1.example.com"
476480
}
477481

478482
if strings.HasPrefix(path, "/app2") {
479-
return "http://app2.example.com" == origin
483+
return origin == "http://app2.example.com"
480484
}
481485

482486
// app 3 allows all origins

0 commit comments

Comments
 (0)