chore: use common header parsing

This commit is contained in:
Grendgi
2026-06-17 13:54:04 +03:00
parent 1a84c04314
commit aad9fa1b4a
2 changed files with 2 additions and 19 deletions

View File

@@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"log/slog" "log/slog"
"net/http" "net/http"
"strings"
) )
func writeJSON(w http.ResponseWriter, status int, v any) { func writeJSON(w http.ResponseWriter, status int, v any) {
@@ -26,19 +25,3 @@ func decodeJSON(r *http.Request, v any) error {
defer r.Body.Close() defer r.Body.Close()
return json.NewDecoder(r.Body).Decode(v) return json.NewDecoder(r.Body).Decode(v)
} }
func csvHeader(r *http.Request, key string) []string {
raw := r.Header.Get(key)
if raw == "" {
return nil
}
parts := strings.Split(raw, ",")
out := make([]string, 0, len(parts))
for _, p := range parts {
p = strings.TrimSpace(p)
if p != "" {
out = append(out, p)
}
}
return out
}

View File

@@ -763,9 +763,9 @@ func allowedOfficeFormat(format string) bool {
} }
func subordinates(r *http.Request) []string { func subordinates(r *http.Request) []string {
ids := csvHeader(r, "X-User-Subordinates") ids := commonmw.HeaderCSV(r, "X-User-Subordinates")
if len(ids) == 0 { if len(ids) == 0 {
ids = csvHeader(r, "X-User-Subordinate-Ids") ids = commonmw.HeaderCSV(r, "X-User-Subordinate-Ids")
} }
return ids return ids
} }