magento-turpentine
magento-turpentine copied to clipboard
Dummy request from referrer affects current URL in cached blocks
Hi,
I have a problem related to getting the current URL, from the request object, in cached blocks that are loaded through the ESI controller.
In the getBlockAction in the ESI controller you have the following code @line 72:
if( $referer = Mage::helper( 'core/http' )->getHttpReferer() ) {
$dummyRequest = Mage::helper( 'turpentine/esi' )
->getDummyRequest( $referer );
}
This creates a dummy request block based on the referrer. The problem with this is that when you try and get the current URL from the request object, it is always the referring URL or your dummy request URL (checkout/cart).
An example of where this happens is in the language switcher template. This gets the current URL from the Store object, which generates the language switch URL from the request. This causes the language switcher to always take you back to the last page you visited or to the checkout/cart page.
Could it be possible to populate the session with the current URL before the cache blocks are loaded and then use that to create the dummy request? Alternatively, maybe you could send an encoded referrer param in the Esi request, similar to what Magento does for it's login redirects.
Otherwise this module is working flawlessly and has massively increased the speed of our application. Keep up the great work.
Sorry to comment on a closed issue but I have the similar / same problem as this, and I wonder if you have a suggestion / solution.
basically we have our url structure set up like this - http://maglife.co.uk/2009/03/30/running-multiple-magento-stores-on-multiple-domains-from-a-single-indexphp/
so say a request comes in for somedomain/en/ - the web server launches the specific store based on the url, but removes the /en/ from the $_SERVER['REQUEST_URI'] so magento sees / rather than /en - this allows us to have a single magento install managing multiple languages over multiple domains all with nice /en/ /fr/ /de/ urls (with the ___store)query string parameter being set in index.php based on the choice). This however is problematic with turpentine for similar reasons as above.
with turpentine/varnish enabled - In our store (language) switcher if you visit via somedomain/en/ the urls in the store switcher are created as
http://somedomain/de/en/ http://somedomain/nl/en/ http://somedomain/fr/en/
which doesn't work. I don't really understand the esicontroller code yet (nor exactly how all the caching works), but I tracked the problem to the same place as the original reporter above.
My current solution is to strip the language path from the referer, but there is still the problem it doesn't stay at the current page. in fact it always seems to go to the root (in my case the referer url is always set to the base link url it seems as _getRefererUrl() just returns Mage::app()->getStore()->getBaseUrl();)
This all works fine without the caching - is this something that I can workaround, or a limitation ?
Many thanks for your time.
Why was this marked closed btw ? as the problem the original poster refers to seems to still exist ?
This seems to fix it for me but I would be interested in comments - is this likely to break anything else - I am passing in Base Url + $_SERVER['REQUEST_URI'] as sending in Mage::helper('core/url')->getCurrentUrl(); although it gets the current url path, the doubled up language path still happens - I assume normally when rendering this block and working out the urls magento has more information so constructs the urls differently (basically getCurrentUrl in the language block doesn't work correctly unless we do this).
Sending in the store base url and the already adjusted $_SERVER['REQUEST_URI'] (which does not contain the language code in the url) makes it behave how I want. Obviously we have a slightly different case from other users due to the way we modify how we handle the URLS as described in the blog article linked in previous comment.
Index: community/Nexcessnet/Turpentine/Model/Observer/Esi.php
===================================================================
--- community/Nexcessnet/Turpentine/Model/Observer/Esi.php (revision 2040)
+++ community/Nexcessnet/Turpentine/Model/Observer/Esi.php (working copy)
@@ -286,6 +286,7 @@
$scopeParam = $esiHelper->getEsiScopeParam();
$methodParam = $esiHelper->getEsiMethodParam();
$esiData = new Varien_Object();
+ $esiData->setCurrentUrl( Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . $_SERVER['REQUEST_URI'] );
$esiData->setStoreId( Mage::app()->getStore()->getId() );
$esiData->setDesignPackage( Mage::getDesign()->getPackageName() );
$esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) );
Index: community/Nexcessnet/Turpentine/controllers/EsiController.php
===================================================================
--- community/Nexcessnet/Turpentine/controllers/EsiController.php (revision 2040)
+++ community/Nexcessnet/Turpentine/controllers/EsiController.php (working copy)
@@ -89,7 +89,7 @@
Mage::app()->setCurrentStore(
Mage::app()->getStore( $esiData->getStoreId() ) );
$appShim = Mage::getModel( 'turpentine/shim_mage_core_app' );
- if( $referer = $this->_getRefererUrl() ) {
+ if( $referer = $esiData->getCurrentUrl() ) {
$referer = htmlspecialchars_decode( $referer );
$dummyRequest = Mage::helper( 'turpentine/esi' )
->getDummyRequest( $referer )
This seems to be a bug? Consider following request flow from user:
[1] http://www.mystore.com/category/?filter_by=price
[2] http://www.mystore.com/category/
While fetching [2] Turpentine would use [1] as current URL.
# Nexcessnet_Turpentine_EsiController::getBlockAction(), line ~92
if( $referer = $this->_getRefererUrl() ) {
$referer = htmlspecialchars_decode( $referer );
$dummyRequest = Mage::helper( 'turpentine/esi' )
->getDummyRequest( $referer );
} else {
However on direct hit to [2] (without http referer set) Turpentine would use different URL (in my case it seems to be http://www.mystore.com/). As some blocks rely on request parameters the same call may produce different results even though "raw" call (i.e. without Varnish & Turpentine) does not depend neither on cookie nor referrer.
Shouldn't Turpentine use [2] as current URL for dummy request?
Furthermore the if clause seems to always be true. When referrer is empty Magento seems to return Mage::app()->getStore()->getBaseUrl();
From my understanding it isn't possible to pass URL of original request to ESI request in Varnish prior to version 4.1 Only in version 4.1 Varnish introduced req_top object which includes necessary information to pass URL of the top level (non ESI) request to ESI requests.
Got this too. When coming from a page (referrer) the url in de ESI block is that of the referrer instead of the current url.
