mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2026-01-28 09:31:13 +00:00
port most routes
This commit is contained in:
22
utils/accepts.go
Normal file
22
utils/accepts.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Accepts(r *http.Request, format string) bool {
|
||||
format = strings.ToLower(format)
|
||||
group := strings.Split(format, "/")[0] + "/*"
|
||||
header := r.Header.Get("Accept")
|
||||
if header == "" {
|
||||
return false
|
||||
}
|
||||
for _, mime := range strings.Split(header, ",") {
|
||||
mime = strings.ToLower(strings.TrimSpace(strings.SplitN(mime, ";", 2)[0]))
|
||||
if mime == "*/*" || mime == format || mime == group {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user