chore: use common header parsing
This commit is contained in:
@@ -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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user