From 554a3f1abf3261a1fbf35acc1a14eea56aa424b8 Mon Sep 17 00:00:00 2001 From: overallteach Date: Wed, 11 Jun 2025 19:54:23 +0800 Subject: [PATCH] refactor: use slices.Contains to simplify code Signed-off-by: overallteach --- nil/services/rpc/internal/http/server.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nil/services/rpc/internal/http/server.go b/nil/services/rpc/internal/http/server.go index dd3599d3f..4f698f9b4 100644 --- a/nil/services/rpc/internal/http/server.go +++ b/nil/services/rpc/internal/http/server.go @@ -6,6 +6,7 @@ import ( "fmt" "mime" "net/http" + "slices" "strconv" "strings" @@ -121,10 +122,8 @@ func (s *Server) validateRequest(r *http.Request) (int, error) { // Check content-type if mt, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")); err == nil { - for _, accepted := range s.acceptedContentTypes { - if accepted == mt { - return 0, nil - } + if slices.Contains(s.acceptedContentTypes, mt) { + return 0, nil } } // Invalid content-type