Barrier to implementing web content compression in mod_perl

[prev] [thread] [next] [Date index for 2005/01/30]

From: Alex Greg
Subject: Barrier to implementing web content compression in mod_perl
Date: 21:54 on 30 Jan 2005
Hi,


I've been trying for some considerable time now to implement web
content compression for our application, but it seems impossible
without a rewrite.


Our application is a (I assume) fairly typical Apache::Registry
application. It used to run under mod_cgi but we're now running it
under mod_perl for the obvious performance gains. HTTP headers are
printed via a subroutine print_content_type:

sub print_content_type
{
	my ($content_type) = @_;
	
	if (!$content_type)
	{
		print "Content-type: text/html\n\n";
	}
	else
	{
		print "Content-type: $content_type\n\n";
	}
}

We have a few hundred .cgi files which are entry points for the user;
these are simple stubs that then call an MVC controller module for
that particular cgi. After print_content_type has been called to send
the appropriate HTTP headers, the body of the HTTP response is then
printed to standard output.

The problem I have found is that when I modify print_content_type as follows:

sub print_content_type
{
	my ($content_type) = @_;
	
	my $r = Apache->request();
	
	$r = $r->filter_register;
	$fh = $r->filter_input();
	
	if (!$content_type)
	{
		$r->send_http_header("text/html");
	}
	else
	{
		$r->send_http_header($content_type);
	}
}

in order to register our application with the Apache::RegistryFilter
chain (which is required to use either Apache::Dynagzip or
Apache::Compress), I get the following in the error log:

[Sat Dec 25 01:36:32 2004] [error] Not a HASH reference at
/usr/lib/perl5/site_perl/5.8.3/Apache/Filter.pm line 197.

and the page throws a 500 Internal Server Error. Apparently this is
because "Apache->request is broken in terms of subclassing - it won't
return the subclass object."
(http://maclux-rz.uibk.ac.at/maillists/axkit-users/msg01214.shtml)

It seems that without using Apache->request or reworking our entire
application (over 500,000 lines of code), I can't get Apache::Filter
to recognise the Content-type header we're sending, and it gets
overridden with the default text/html from Apache::Dynagzip.


Has anyone else come across this problem, or can suggest a solution or
alternative approach? I've discussed it with Slava Bizyayev
(http://marc.theaimsgroup.com/?l=apache-modperl&m=110435780804427&w=2)
before, but I can't rework our application code into a handler as
there's far too much of it. I've also emailed Ken Williams regarding
the "Not a HASH reference" error, but the solution he suggested (using
"$r = Apache->request->pnotes('filterobject')" instead of "$r =
Apache->request" produced the same error.


Regards,


-- Alex

Barrier to implementing web content compression in mod_perl
Alex Greg 21:54 on 30 Jan 2005

Generated at 12:39 on 05 Feb 2005 by mariachi v0.52