- The Apache Request Object
- The HTTP Request Message
- The Client Request
- Accessing Client Request Headers
- Accessing HTML Form Fields
- Reading POSTed Data Manually
- Manipulating Cookies
- Handling File Uploads
- Setting Server Response Headers
- Controlling Caching Behavior
- Sending Server Response Headers
- Setting the Response Status
- Setting Error Headers
- Manipulating Headers with Multiple Like Fields
- Using Subrequests
- Setting Headers for Subrequests
- Short-Circuiting Subrequests
- Getting or Setting the Request Method
- Accessing the Request Object from XS
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*Handlersit only continues authenticating for the main request and avoids needless overhead for any subrequests.