From d57a5b8ba51c28d5f40c45b35525a384e024c284 Mon Sep 17 00:00:00 2001 From: Andrew Kett Date: Tue, 10 Jan 2017 11:35:40 +1300 Subject: [PATCH] use X-Requested-With header in hash so that xhr and standard requests can serve different results and still be varnished. --- .../Nexcessnet/Turpentine/misc/version-2.vcl | 8 ++++++++ .../Nexcessnet/Turpentine/misc/version-3.vcl | 11 ++++++++++- .../Nexcessnet/Turpentine/misc/version-4.vcl | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 2223bedbc..816a9d2b4 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -288,6 +288,14 @@ sub vcl_hash { set req.hash += regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1"); } + # Some extension controllers serve different results for a single url depending on + # whether the request is xhr. prototype and jquery both set X-Requested-With + # headers on ajax requests, we can use them in the hash so that both variations + # are served seperately + if (req.http.X-Requested-With) { + set req.hash += req.http.X-Requested-With + } + return (hash); } diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index a391f2d8d..2dfa0a24d 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -290,7 +290,16 @@ sub vcl_hash { req.http.Cookie ~ "customer_group=") { hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1")); } - + + # Some extension controllers serve different results for a single url depending on + # whether the request is xhr. prototype and jquery both set X-Requested-With + # headers on ajax requests, we can use them in the hash so that both variations + # are served seperately + if (req.http.X-Requested-With) { + std.log("hash_data xhr request - X-Requested-With: " + req.http.X-Requested-With); + hash_data(req.http.X-Requested-With); + } + return (hash); } diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 470183f62..d92c59452 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -310,6 +310,16 @@ sub vcl_hash { req.http.Cookie ~ "customer_group=") { hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1")); } + + # Some extension controllers serve different results for a single url if the + # request is xhr. both prototype and jquery set X-Requested-With headers + # on ajax requests so we can add that to the hash so that both variations + # are served seperately + if (req.http.X-Requested-With) { + std.log("hash_data xhr request - X-Requested-With: " + req.http.X-Requested-With); + hash_data(req.http.X-Requested-With); + } + std.log("vcl_hash end return lookup"); return (lookup); }