Apache2-ModProxyPerlHtml
view release on metacpan or search on metacpan
ModProxyPerlHtml.pm view on Meta::CPAN
#------------------------------------------------------------------------------
# Project : Reverse Proxy HTML link rewriter
# Name : ModProxyPerlHtml.pm
# Language : perl 5
# Authors : Gilles Darold, gilles at darold dot net
# Copyright: Copyright (c) 2005-2022, Gilles Darold - All rights reserved -
# Description : This mod_perl module is a replacement for mod_proxy_html.c
# with far better URL HTML rewriting.
# Usage : See documentation in this file with perldoc.
#------------------------------------------------------------------------------
# This program is free software; you can redistribute it and/or modify it under
# the same terms as Perl itself.
#------------------------------------------------------------------------------
package Apache2::ModProxyPerlHtml;
use strict qw(vars);
use warnings;
require mod_perl2;
use Apache2::Connection ();
use Apache2::RequestRec;
use Apache2::RequestUtil;
use APR::Table;
use APR::URI;
use base qw(Apache2::Filter);
use Apache2::Const -compile => qw(OK DECLINED :conn_keepalive);
use constant BUFF_LEN => 8000;
use Apache2::ServerRec;
use Apache2::URI;
$Apache2::ModProxyPerlHtml::VERSION = '4.1';
%Apache2::ModProxyPerlHtml::linkElements = (
'a' => ['href'],
'applet' => ['archive', 'codebase', 'code'],
'area' => ['href'],
'bgsound' => ['src'],
'blockquote' => ['cite'],
'body' => ['background'],
'del' => ['cite'],
'embed' => ['pluginspage', 'src'],
'form' => ['action'],
'frame' => ['src', 'longdesc'],
'iframe' => ['src', 'longdesc'],
'ilayer' => ['background'],
'img' => ['src', 'lowsrc', 'longdesc', 'usemap'],
'input' => ['src', 'usemap','formaction'],
'ins' => ['cite'],
'isindex' => ['action'],
'head' => ['profile'],
'layer' => ['background', 'src'],
'link' => ['href'],
'object' => ['classid', 'codebase', 'data', 'archive', 'usemap'],
'q' => ['cite'],
'script' => ['src', 'for'],
'table' => ['background'],
'td' => ['background'],
'th' => ['background'],
'tr' => ['background'],
'xmp' => ['href'],
'button' => ['formaction'],
);
sub handler
{
my $f = shift;
my $debug = $f->r->dir_config->get('ProxyHTMLVerbose');
if ($debug && $debug =~ /(on|1)/i) {
$debug = 1;
} else {
$debug = 0;
}
# Thing we do at the first chunk
my $content_type = $f->r->content_type() || '';
unless ($f->ctx) {
$f->r->headers_out->unset('Content-Length');
my @pattern = $f->r->dir_config->get('ProxyHTMLURLMap');
my @rewrite = $f->r->dir_config->get('ProxyHTMLRewrite');
my $contenttype = $f->r->dir_config->get('ProxyHTMLContentType');
$contenttype ||= '(text\/javascript|text\/html|text\/css|text\/xml|application\/.*javascript|application\/.*xml)';
my $badcontenttype = $f->r->dir_config->get('ProxyHTMLExcludeContentType');
$badcontenttype ||= '(application\/vnd\.openxml)';
my @exclude = $f->r->dir_config->get('ProxyHTMLExcludeUri');
my @obfuscation = $f->r->dir_config->get('ProxyHTMLRot13Links');
my $ct = $f->ctx;
$ct->{data} = '';
foreach my $p (@pattern) {
push(@{$ct->{pattern}}, $p);
}
foreach my $p (@rewrite) {
push(@{$ct->{rewrite}}, $p);
}
$ct->{contenttype} = $contenttype;
$ct->{badcontenttype} = $badcontenttype;
foreach my $u (@exclude) {
push(@{$ct->{excluded}}, $u);
}
foreach my $o (@obfuscation) {
my ($elt, $attr) = split(/:/, $o);
if (uc($elt) eq 'ALL') {
$ct->{rot13elements} = 'All';
last;
} else {
$ct->{rot13elements}->{$elt} = $attr;
}
}
$f->ctx($ct);
}
# Thing we do on all invocations
my $ctx = $f->ctx;
while ($f->read(my $buffer, BUFF_LEN)) {
$ctx->{data} .= $buffer;
$ctx->{keepalives} = $f->c->keepalives;
$f->ctx($ctx);
}
# Thing we do at end
( run in 0.690 second using v1.01-cache-2.11-cpan-0d23b851a93 )