5

I have some old mod_perl code that generates dynamic content. I was asked to implement sending an Etag on each reply.

It seems the way to do this might be to add a mod_perl handler, but this content is generated dynamically, so I need to make the Etag a checksum of the response body. I have yet not found a way to get the contents of the response body in a mod_perl handler to checksum it.

How should I dynamically generate Etags based on the response body in mod_perl?

  • 1
    If you can change the mod_perl handler itself, then change it to collect all the content to output (i.e. have a central `$r->print` at the end), so you can add arbitrary headers. If you cannot change it, then writing a [mod_perl2 filter](http://perl.apache.org/docs/2.0/user/handlers/filters.html) could help. – Slaven Rezic Sep 04 '13 at 05:32

1 Answers1

0

If your content is dynamically generated then probably the easiest way to set the etags to totally random numbers. (And this is also the safest way...)

Or maybe you can create a heuristic like creating a hash from the url/get/post parameters. If you can't create this kind of heuristic it means that your internal logic is based on other internal states. (session/etc) So probably the total random etags are the best solution.

Lajos Veres
  • 13,595
  • 7
  • 43
  • 56