Home > Articles > Web Development > Perl

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Short-Circuiting Subrequests

You want to be able to determine whether a request is an actual client request or a subrequest.


Use the is_initial_req() method from the Apache class.

return OK unless $r->is_initial_req;


As you begin to write mod_perl handlers that fold, spindle, and mutilate the different parts of the request cycle, you may find that your custom processing does not really need to happen on every request, just the requests that the client will actually see. For instance, in the prior recipe we checked to see whether the user was allowed to view a particular resource based on the status of the subrequest. However, if you have set up your application such that the user is already authenticated by the time he can run your script, executing the authentication routines again wastes processor cycles.

The is_initial_req() method returns false if the request is the result of a subrequest or internal redirect and true for the main request. The preceding example is the typical idiom for PerlAuth*Handlers—it only continues authenticating for the main request and avoids needless overhead for any subrequests.

  • + Share This
  • 🔖 Save To Your Account