This is an automated email from the ASF dual-hosted git repository.

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 65e7b75  Transform images when a client accepts image/webp.
65e7b75 is described below

commit 65e7b7560e5497997c096400b247f2640652b22e
Author: David Calavera <[email protected]>
AuthorDate: Fri Nov 16 14:44:03 2018 -0800

    Transform images when a client accepts image/webp.
    
    More browsers besides Chrome have started to support webp
    as image format. To advertise their support, they include
    image/webp content type in the Accept header.
    
    This change allows this plugin to detect support for webp
    by checking the Accept header and keeps the old User-Agent
    check for old versions of Chrome.
    
    Signed-off-by: David Calavera <[email protected]>
---
 plugins/experimental/webp_transform/ImageTransform.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/plugins/experimental/webp_transform/ImageTransform.cc 
b/plugins/experimental/webp_transform/ImageTransform.cc
index 68ea938..1f29a88 100644
--- a/plugins/experimental/webp_transform/ImageTransform.cc
+++ b/plugins/experimental/webp_transform/ImageTransform.cc
@@ -92,7 +92,12 @@ public:
   {
     string ctype      = 
transaction.getServerResponse().getHeaders().values("Content-Type");
     string user_agent = 
transaction.getServerRequest().getHeaders().values("User-Agent");
-    if (user_agent.find("Chrome") != string::npos && (ctype.find("jpeg") != 
string::npos || ctype.find("png") != string::npos)) {
+    string accept     = 
transaction.getServerRequest().getHeaders().values("Accept");
+
+    bool webp_supported = accept.find("image/webp") != string::npos || 
user_agent.find("Chrome") != string::npos;
+    bool image_format   = ctype.find("jpeg") != string::npos || 
ctype.find("png") != string::npos;
+
+    if (webp_supported && image_format) {
       TS_DEBUG(TAG, "Content type is either jpeg or png. Converting to webp");
       transaction.addPlugin(new ImageTransform(transaction));
     }

Reply via email to