use X-Requested-With header in hash so that xhr and standard requests… #1341
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some Magento extensions serve different results for a single URL depending on whether the request is XHR or a standard browser request. For example the XHR may return a JSON object whereas the standard request returns an HTML page. For obvious reasons this could cause issues if either result is cached and served for the other request.
I ran into an example of this using a third party layered navigation extension. The filtered products were loaded in with ajax and injected into the page, the browser URL was then updated with the history API to reflect the new page that was loaded. If the user then refreshed the page they would be served a JSON object that was originally served by the ajax request.
This wouldn't be an issue if we were able to cache ajax requests separately. Prototype and jQuery both set X-Requested-With headers with requests made through their respective Ajax tools, if this header is set we can add it to the cache hash meaning that they will be cached differently. I have implemented this solution in my development environment and it has resolved my issue, I don't believe it will affect existing functionality so it could be worth adding it to the default VCL to avoid similar problems.
This pull requests contains fixes for varnish versions 2, 3 and 4 vcl. Unfortunately I only have a working version of v4 set up so I haven't been able to test the versions 2 and 3 vcl files.