This is a great module to rebuild proxy cache entries for anonymous users, but it lacks the ability to send specific headers when calling httprl_request.
This would be needed for some specific server configurations, or to be able to generate cache variations depending on user roles, or any defined rule.
Adding a simple hook adds this ability by altering the headers, and using an additional foreach:
183 // Default HTTP request options for anonymous users.
184 $recacher_role_options['anonymous'] = array(
185 'timeout' => 90,
186 // We are using BLOCKING requests so as not to strain the target website with parallel requests for uncached URLs.
187 'blocking' => TRUE,
188 // Accept-Encoding is crucial - this is how most browsers, but also GoogleBot, request content. If we leave it out, most browsers would still find the cache cold!
189 'headers' => array('Accept-Encoding' => 'gzip'),
190 );
191
192 // Let other modules alter options and headers sent via HTTPRL.
193 module_invoke_all('recacher_role_options', $recacher_role_options);
194
195 foreach ($dburls as $dburl) {
196 foreach($recacher_role_options as $role => $options){
197 // Queue up the request.
198 httprl_request($dburl, $options);
199 }
200 }
These modifications do not alter the behavior of the module and add more rewarm possibilities.
Attached patch adds this hook.
Comments
Comment #2
adrien.felipe commentedComment #3
adrien.felipe commentedCorrecting typos.
Comment #5
vacilando commentedNice stuff, Adrien. Committed to DEV. Please test and let us know whether it works as expected in your situation.
Comment #8
adrien.felipe commentedThanks for commiting the patch Vacilando.
Here comes another patch to fix the failed test to apply.
Comment #9
vacilando commentedComment #12
vacilando commented@adrien.felipe -- if you can fix the patch so that it passes testing I'll be happy to include your contribution in the upcoming stable release of the module.
Comment #13
vacilando commentedDisregard the failed tests -- they actually show because this module does not define any tests yet. See #2645590: Ensure that simpletest job doesn't "fail" testing if no tests are present .
If the functionality is OK we can close this issue as fixed.
Comment #14
damienmckennaAny particular reason that drupal_alter() wasn't used for this? It would seem like the obvious choice.
Comment #15
damienmckennaProbably too late, but this is what drupal_alter() would look like.
Comment #16
damienmckennaSorry, that was the wrong file, this is the one with hook_recacher_role_options_alter.
Comment #17
adrien.felipe commentedI can't find a reason why drupal_alter() would not have been used in this case, but I do remember discussing it though.
Once we survived blackfriday I'll give a try to your patch, thanks.
Comment #18
damienmckennaThis adds back the old hook but in the API docs marks it as being deprecated, that way it won't break sites already using the previous hook.
Comment #19
damienmckennaRelated: #2831552: Add hook to allow the expire_cache URLs to be changed
Comment #21
vacilando commentedThanks, that is very considerate with regards to users that may already have implemented the earlier hook.
Committed to 7.x-1.x-dev!