From 99f36b35f76394534fa7ec0dfab121c8aeb81817 Mon Sep 17 00:00:00 2001 From: n0vad3v Date: Tue, 30 Jun 2020 16:12:35 +0800 Subject: [PATCH] Render origin image on MSIE --- helper.go | 6 +++++- helper_test.go | 4 ++-- router.go | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/helper.go b/helper.go index 5e63526..b17a143 100644 --- a/helper.go +++ b/helper.go @@ -61,7 +61,7 @@ func GenWebpAbs(RawImagePath string, ExhaustPath string, ImgFilename string, req return cwd, WebpAbsolutePath } -func isSafari(UA string) bool { +func goOrigin(UA string) bool { // for more information, please check test case if strings.Contains(UA, "Firefox") || strings.Contains(UA, "Chrome") { // Chrome or firefox on macOS Windows @@ -72,5 +72,9 @@ func isSafari(UA string) bool { } else { return true } + if strings.Contains(UA, "rv:11.0") || strings.Contains(UA, "MSIE") { + // MSIE + return true + } return false } diff --git a/helper_test.go b/helper_test.go index 33b2170..a3d156f 100644 --- a/helper_test.go +++ b/helper_test.go @@ -58,7 +58,7 @@ func TestGenWebpAbs(t *testing.T) { } } -func TestisSafari(t *testing.T) { +func TestgoOrigin(t *testing.T) { // reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox // https://developer.chrome.com/multidevice/user-agent#chrome_for_ios_user_agent @@ -89,7 +89,7 @@ func TestisSafari(t *testing.T) { for browser, is := range testCase { - if is != isSafari(browser) { + if is != goOrigin(browser) { t.Errorf("[%v]:[%s]", is, browser) } } diff --git a/router.go b/router.go index abeda26..ef0788d 100644 --- a/router.go +++ b/router.go @@ -20,9 +20,9 @@ func Convert(ImgPath string, ExhaustPath string, AllowedTypes []string, QUALITY var ImgFilename = path.Base(reqURI) // pure filename, 123.jpg var finalFile string // We'll only need one c.sendFile() var UA = c.Get("User-Agent") - done := isSafari(UA) + done := goOrigin(UA) if done { - log.Infof("A Safari user has arrived...%s", UA) + log.Infof("A Safari/IE/whatever user has arrived...%s", UA) c.SendFile(RawImageAbs) return }