Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 29643 invoked from network); 1 Jan 2009 13:03:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Jan 2009 13:03:24 -0000 Received: (qmail 38356 invoked by uid 500); 1 Jan 2009 13:03:19 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 38333 invoked by uid 500); 1 Jan 2009 13:03:19 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 38324 invoked by uid 99); 1 Jan 2009 13:03:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jan 2009 05:03:19 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [212.85.38.174] (HELO popeye.combios.es) (212.85.38.174) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jan 2009 13:03:10 +0000 Received: from [192.168.245.129] (p549EB016.dip0.t-ipconnect.de [84.158.176.22]) (authenticated bits=0) by popeye.combios.es (8.13.8/8.13.8/Debian-3) with ESMTP id n01D2mbD026516 for ; Thu, 1 Jan 2009 14:02:49 +0100 Message-ID: <495CBE12.2030302@ice-sa.com> Date: Thu, 01 Jan 2009 13:58:58 +0100 From: =?UTF-8?B?QW5kcsOpIFdhcm5pZXI=?= Reply-To: mod_perl list User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: mod_perl list Subject: Re: HTTP Response Headers fixup References: <495B5878.6050402@ice-sa.com> <495B9C1D.3000800@norchemlab.com> In-Reply-To: <495B9C1D.3000800@norchemlab.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV 0.92.1/8822/Thu Jan 1 03:24:59 2009 on popeye.combios.es X-Virus-Status: Clean X-Virus-Checked: Checked by ClamAV on apache.org As a complement to this thread, I would like to reproduce an answer received on the Tomcat list, from Rainer Jung, the developer/maintainer of the mod_jk module. It explains why I wasn't (and can't) get any success doing what I wanted with either mod_headers or a mod_perl connection output filter (which I tried). Rainer Jung : Apache 2 has hooks for modules, but also filters. The hooks allow to interact with request processing at certain stages and the modules decide, whether they allow other modules to be called in the same hook. mod_headers is a filter, which allows to manipulate requests and responses much like servlet filters during the reading and writing of request resp. response. Thus you can use mod_headers to change headers after they are returned by mod_jk. Unfortunately the Content-Type header is a different beast. Inside Apache it is not only a response header, but a more complex data type. You can set a different Content-Type header with mod_headers, but since the internal structure remains unchanged it will be overwritten again by Apache. As a result I see no way to change an existing character set in a Content-Type header. > I have tried changing the Content-Type header in a servlet filter under > Tomcat. However, that also has the side-effect that the servlet then, > for its response, really uses the new character encoding specified in > the header, to produce its response. > That is not what I want here, because the problem is that the servlet > response is already correct (in the iso-8859-2 encoding), it is just > that the Content-Type header is incorrect and does not match the real > charset of the response. The underlying reason for all that stuff is > obscure and OT here, but that is really what happens. See javax.servlet.ServletResponseWrapper. A filter can replace request and/or response with a custom wrapper object. Whenever the servlet then calls a method of the request or response object, your custom object is called. Your custom response wrapper extends the standard one, which itself lets all methods call through to the wrapped response. You can then implement individual methods in a different way. You could for instance overwrite setCharacterEncoding(java.lang.String charset) to set something else, then demanded by the caller (e.g. iso-8859-2 instead of iso-8859-1), and getCharacterEncoding() to return something different, from what you actually set. The filter can inspect e.g. the URL to decide, whether it should wrap the response or not. This mechanism can be used without any changes to the existing webapp code, you only need to add your filter and wrapper to the webapp, and of course add the filter to web.xml. Regards, Rainer