Philippe M. Chiasson wrote:
On 22/3/09 15:25, Louis-David Mitterrand wrote:
[...]
Hi.
There was a thread here some time in the past (late 2008 ?) between Torsten Foetsch and myself, talking about overriding this Content-Type header. As I recall, this particular header is somewhat special, because the response's content-type is part of a separate Apache structure related to the request, which Apache uses when outputting the request. The practical result is that even when you explicitly set the content-type in your request-processing code (like you do in your original post), Apache will later on overwrite this header again, using information from that other structure. That's what gives the impression that your original code does not work. It does, but what it sets gets overwritten later on.

The solution is to use an output filter (which runs after the request processing has taken place). Sample working code below. In my case, I basically wanted to always override the "charset" attribute set by an application, but it should work in other cases. Be sure to check carefully where you apply it though, since you proably do not want to override all your Content-Type headers.

Configuration in httpd.conf :
<Location /blabla>
  PerlOutputFilterHandler AM::FixStarWebCharset
</Location>


package AM::FixStarWebCharset;
# File : AM/FixStarWebCharset.pm
# Fixes servlet-generated Content-Type header
# Idea from Torsten Foetsch.

$AM::FixStarWebCharset::VERSION = '0.01';

use strict;
use warnings FATAL => 'all';

use mod_perl2 2.000001;

use base qw(Apache2::Filter);
use Apache2::Const ();

use constant DEBUG => 0;

sub handler : FilterRequestHandler {
my ($f, $bb) = @_;
my $r = $f->r;
    $r->content_type("text/html; charset=ISO-8859-2");
    # should we also remove ourselves ?
    return Apache2::Const::DECLINED;
}
1;

Reply via email to