diff options
author | George Goldberg <george@gberg.me> | 2018-03-13 13:36:23 +0000 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2018-03-13 13:36:23 +0000 |
commit | fadcdd271a68b38571b75d1d38ab023f940ac83a (patch) | |
tree | 7f413edd35401b54b2f4eb4a687da1ac273bcd4b /web/web.go | |
parent | b66e4bc932ed76c1cfd2b5f4ec0cfce70cd9fbb4 (diff) | |
parent | f2d26801b9647715fb43af873354d8def753868b (diff) | |
download | chat-fadcdd271a68b38571b75d1d38ab023f940ac83a.tar.gz chat-fadcdd271a68b38571b75d1d38ab023f940ac83a.tar.bz2 chat-fadcdd271a68b38571b75d1d38ab023f940ac83a.zip |
Merge branch 'master' into advanced-permissions-phase-1
Diffstat (limited to 'web/web.go')
-rw-r--r-- | web/web.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/web/web.go b/web/web.go index e0edd1b7a..22fe43923 100644 --- a/web/web.go +++ b/web/web.go @@ -8,12 +8,12 @@ import ( "strings" "github.com/NYTimes/gziphandler" + "github.com/avct/uasurfer" l4g "github.com/alecthomas/log4go" "github.com/mattermost/mattermost-server/api" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" - "github.com/mssola/user_agent" ) func Init(api3 *api.API) { @@ -65,26 +65,27 @@ func pluginHandler(config model.ConfigFunc, handler http.Handler) http.Handler { }) } -var browsersNotSupported string = "MSIE/8;MSIE/9;MSIE/10;Internet Explorer/8;Internet Explorer/9;Internet Explorer/10;Safari/7;Safari/8" +// Due to the complexities of UA detection and the ramifications of a misdetection only older Safari and IE browsers throw incompatibility errors. -func CheckBrowserCompatability(c *api.Context, r *http.Request) bool { - ua := user_agent.New(r.UserAgent()) - bname, bversion := ua.Browser() +// Map should be of minimum required browser version. +var browserMinimumSupported = map[string]int{ + "BrowserIE": 11, + "BrowserSafari": 9, +} - browsers := strings.Split(browsersNotSupported, ";") - for _, browser := range browsers { - version := strings.Split(browser, "/") +func CheckClientCompatability(agentString string) bool { + ua := uasurfer.Parse(agentString) - if strings.HasPrefix(bname, version[0]) && strings.HasPrefix(bversion, version[1]) { - return false - } + if version, exist := browserMinimumSupported[ua.Browser.Name.String()]; exist && ua.Browser.Version.Major < version { + return false } return true } func root(c *api.Context, w http.ResponseWriter, r *http.Request) { - if !CheckBrowserCompatability(c, r) { + + if !CheckClientCompatability(r.UserAgent()) { w.Header().Set("Cache-Control", "no-store") page := utils.NewHTMLTemplate(c.App.HTMLTemplates(), "unsupported_browser") page.Props["Title"] = c.T("web.error.unsupported_browser.title") |