diff options
author | Alex Moon <moonmeister@users.noreply.github.com> | 2018-03-06 13:22:07 -0800 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2018-03-06 21:22:07 +0000 |
commit | 309594cedf9f39be5f557de34cc741e218cd3668 (patch) | |
tree | ed7e6487fed774a7609073de322339186f1683d6 /web/web.go | |
parent | 6b3c9a480a0174cc7d1b17d0a0d874eedecc2dd3 (diff) | |
download | chat-309594cedf9f39be5f557de34cc741e218cd3668.tar.gz chat-309594cedf9f39be5f557de34cc741e218cd3668.tar.bz2 chat-309594cedf9f39be5f557de34cc741e218cd3668.zip |
[PLT-7574] Update and Simplify Compatibility Check and Replace UA Dependency (#7427)
* Add fix to not run browser check on Mobile Browsers or the App
* remove non safari and IE checks
* Replace useragent checking dependency and update UA tests
* change some wording
* change dependancy again to one with compatible licence
* Fix typos and clarify wording
* fix typo and comvert tests to use array
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") |