Appendix A. mod_perl Recipes
This appendix acts as a mini-cookbook for mod_perl. As we’ve mentioned many times in this book, the mod_perl mailing list is a terrific resource for anyone working with mod_perl. Many very useful code snippets and neat techniques have been posted to the mod_perl mailing list. In this appendix, we present the techniques that you will find most useful in your day-to-day mod_perl programming.
Emulating the Authentication Mechanism
You can authenticate users with your own mechanism (instead of the standard one) but still make Apache think that the user was authenticated by the standard mechanism. Set the username with:
$r->connection->user('username');Now you can use this information, for example, during logging, so that you can have your “username” passed as if it was transmitted to Apache through HTTP authentication.
Reusing Data from POST Requests
What happens if you need to
access the POSTed data
more than once. For example, suppose you need to reuse it in
subsequent handlers of the same request? POSTed
data comes directly from the socket, and at the low level data can be
read from a socket only once. You have to store it to make it
available for reuse.
But what do you do with large multipart file uploads? Because
POSTed data is not all read in one clump,
it’s a problem that’s not easy to
solve in a general way. A transparent way to do this is to switch the
request method from POST to GET
and store the POST data in the query string. The
handler in Example ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access