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

adrien.felipe created an issue. See original summary.

adrien.felipe’s picture

adrien.felipe’s picture

Issue summary: View changes

Correcting typos.

  • Vacilando committed 0cc6e61 on 7.x-1.x
    Issue #2713779 by adrien.felipe: Hook to add / alter headers sent to...
vacilando’s picture

Status: Active » Needs review

Nice stuff, Adrien. Committed to DEV. Please test and let us know whether it works as expected in your situation.

Status: Needs review » Needs work

The last submitted patch, 2: recacher-httprl_options_hook-2713779-1-7.patch, failed testing.

The last submitted patch, 2: recacher-httprl_options_hook-2713779-1-7.patch, failed testing.

adrien.felipe’s picture

StatusFileSize
new506 bytes

Thanks for commiting the patch Vacilando.
Here comes another patch to fix the failed test to apply.

vacilando’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: recacher-httprl_options_hook-2713779-8.patch, failed testing.

The last submitted patch, 8: recacher-httprl_options_hook-2713779-8.patch, failed testing.

vacilando’s picture

@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.

vacilando’s picture

Status: Needs work » Needs review

Disregard 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.

damienmckenna’s picture

Any particular reason that drupal_alter() wasn't used for this? It would seem like the obvious choice.

damienmckenna’s picture

StatusFileSize
new119 bytes

Probably too late, but this is what drupal_alter() would look like.

damienmckenna’s picture

StatusFileSize
new1.35 KB

Sorry, that was the wrong file, this is the one with hook_recacher_role_options_alter.

adrien.felipe’s picture

I 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.

damienmckenna’s picture

StatusFileSize
new1.71 KB

This 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.

vacilando’s picture

Status: Needs review » Fixed

Thanks, that is very considerate with regards to users that may already have implemented the earlier hook.

Committed to 7.x-1.x-dev!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.