From e45ca996acd6039a0dded9795659f47f9bd51511 Mon Sep 17 00:00:00 2001 From: n0vad3v Date: Sun, 9 Feb 2020 19:35:41 +0800 Subject: [PATCH] Added Safari support --- README.md | 2 +- webp_server.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1dd51c..16ac364 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ your files are at `/var/www/image/pics/tsuki.jpg`, then `IMG_PATH` shall be `/va 3. Let Nginx to `proxy_pass http://localhost:3333/;` ## TODO -- [ ] This version doesn't support header-based-output, which means Safari users will not see the converted `webp` images, this should be fixed in later releases. +- [x] This version doesn't support header-based-output, which means Safari users will not see the converted `webp` images, this should be fixed in later releases. - [ ] Multi platform support. ## build your own binary diff --git a/webp_server.go b/webp_server.go index d743adb..317fe68 100644 --- a/webp_server.go +++ b/webp_server.go @@ -123,6 +123,13 @@ func main() { return } + // Check for Safari users + UA := c.Get("User-Agent") + if strings.Contains(UA,"Safari") && !strings.Contains(UA,"Chrome") && !strings.Contains(UA,"Firefox"){ + c.SendFile(ImgAbsolutePath) + return + } + if imageExists(WebpAbsolutePath) { c.SendFile(WebpAbsolutePath) } else {