rpc: use slices.Contains

Signed-off-by: deepdring <deepdrink@icloud.com>
This commit is contained in:
deepdring 2025-08-14 22:39:10 +08:00
parent 2dbb580f51
commit b8c237aea8

View file

@ -27,6 +27,7 @@ import (
"mime"
"net/http"
"net/url"
"slices"
"strconv"
"sync"
"time"
@ -351,12 +352,10 @@ 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 acceptedContentTypes {
if accepted == mt {
if slices.Contains(acceptedContentTypes, mt) {
return 0, nil
}
}
}
// Invalid content-type
err := fmt.Errorf("invalid content type, only %s is supported", contentType)
return http.StatusUnsupportedMediaType, err