PAPI::RewritingProxy - mod_perl Apache handler to process requests for remote resources through a PAPI PoA


 sub handler {
    my $r = shift;
    $r->set_handlers(PerlAccessHandler => undef);
    $r->set_handlers(PerlHandler => [PAPI::RewritingProxy]);


The handler function in this package processes requests, redirecting them according to the settings of either the Remote_URL or Remote_Domain configuration parameter. The URI to be requested is build according to the value of Strip_Location, and once any rewriting rule defined by PAPI_Request_Redirect is applied. The handler is able to set the local IP address to be used according to the value of the parameter Local_IP_Address (if set). If the parameter Proxy_Server has been specified, the handler will use it to satisfy the request. If HTTP Authentication is in use, either at any remote server or at the proxy server, the HTTP_Auth configuration parameter can be employed to seamlessly access those restricted resources. If the requested URL matches any expression defined by the applicable Reject_URL_Pattern directives, the PAPI proxy will return a 403 FORBIDDEN code in response to the request.

If the request (once translated into the remote server/domain) matches any of the URLs identified for automatic form processing by the configuration directive Form_Processor, the handler will proceed to request the specified URL, fill the defined values into the form and send it to the remote server. The response sent back to the user will be that sent by the remote server in response to the automatically filled form.

The handler is able to access large remote content by chunks, passing them to the requesting browser as they become available at the proxy. The configuration directive Proxy_Chunk_Size (32 KB by default) controls this behavior.

Once the response from the remote server is received, contents are rewritten according to:

1. The value of Remote_URL or Remote_Domain.

2. The setting of the Rewrite_MIME_Types configuration parameter.

3. The rules defined by the Rewrite_URL_Pattern configuration parameters.

4. The rules defined by the PAPI_Redirect, PAPI_Redirect_by_URL, PAPI_POST_Redirect, and PAPI_Header_Redirect configuration parameters.

5. The setting of the Redirect_All configuration parameter.

The following elements are processed by the rewriting procedures:

1. Contents of Location and (non-standard, but very common) Refresh HTTP headers (redirects).

2. The href attribute of the a, area, base, and link HTML tags.

3. The content attribute of the meta HTML tag.

4. The src attribute of the frame, iframe, img, input, and script HTML tags.

5. The action attribute of the form HTML tag.

6. The background attribute of the body and td HTML tags.

7. The value attribute of the input and option HTML tags.

8. The contents of any script and style HTML element.

9. JavaScript and style attributes of HTML tags.

10. Contents of the variables sent through the POST method.

11. Values of headers sent to the remote server.


PAPI Configuration