1
0
mirror of https://github.com/rancher/norman.git synced 2025-06-05 21:43:04 +00:00
norman/parse/browser.go

19 lines
420 B
Go
Raw Permalink Normal View History

2017-11-11 04:44:02 +00:00
package parse
2017-10-16 02:23:15 +00:00
import (
"net/http"
"strings"
)
func IsBrowser(req *http.Request, checkAccepts bool) bool {
accepts := strings.ToLower(req.Header.Get("Accept"))
userAgent := strings.ToLower(req.Header.Get("User-Agent"))
if accepts == "" || !checkAccepts {
accepts = "*/*"
}
// User agent has Mozilla and browser accepts */*
2017-11-11 04:44:02 +00:00
return strings.Contains(userAgent, "mozilla") && strings.Contains(accepts, "*/*")
2017-10-16 02:23:15 +00:00
}