From fc9305756b095d6a0aede51f06fc85933647a25f Mon Sep 17 00:00:00 2001 From: iBug Date: Wed, 16 Aug 2023 10:06:09 +0800 Subject: [PATCH] Replace 200, HEAD and OPTIONS with constants from net/http (#243) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What type of PR is this? (check all applicable) - [x] Refactor - [ ] Feature - [ ] Bug Fix - [ ] Optimization - [ ] Documentation Update ## Description A previous commit (#241) replaced most HTTP constants with those from standard library `net/http`, but some was missed. This PR catches 3 of them. ## Related Tickets & Documents - Related Issue: None - Closes: None ## Added/updated tests? - [ ] Yes - [x] No, and this is why: Trivial changes, tests not required - [ ] I need help with writing tests ## Run verifications and test - [ ] `make verify` is passing (which I believe is not my fault) - [x] `make test` is passing --- cors.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cors.go b/cors.go index 42892bd..8af9c09 100644 --- a/cors.go +++ b/cors.go @@ -26,14 +26,14 @@ type cors struct { type OriginValidator func(string) bool var ( - defaultCorsOptionStatusCode = 200 - defaultCorsMethods = []string{http.MethodGet, "HEAD", http.MethodPost} + defaultCorsOptionStatusCode = http.StatusOK + defaultCorsMethods = []string{http.MethodGet, http.MethodHead, http.MethodPost} defaultCorsHeaders = []string{"Accept", "Accept-Language", "Content-Language", "Origin"} // (WebKit/Safari v9 sends the Origin header by default in AJAX requests). ) const ( - corsOptionMethod string = "OPTIONS" + corsOptionMethod string = http.MethodOptions corsAllowOriginHeader string = "Access-Control-Allow-Origin" corsExposeHeadersHeader string = "Access-Control-Expose-Headers" corsMaxAgeHeader string = "Access-Control-Max-Age"