hi stas

Stas Bekman wrote:
allan juul wrote:
[...]

But if you use a mod_perl filter you will still hit the issue of unknown content-length header.



yes, of course that's true. there goes caching (:


Not really. Nothing prevents you from buffering up the response, process it, set the content-length header and make the document cache-able.

ok, eh how do i that. you mean instead of printing to STDOUT, collect data in a buffer, then set the calculated Content-Length, then print data?


anyway, it's pretty strange. it seems i'm able to set the Content-Length when i use the mod_perl_filter and do *not* reverse proxy. see both headers below. the strange things is that i'm not allowed at all to set the standard Content-Length, but indeed allowed to set a custom one called Content-Length2. and even stranger is that this custom header presents a correct value when *not* proxying but "0" when proxying. i use the exact same mod_perl code, also supplied below. the actual filtering of data content works in both cases.

all this is on windows.


./allan


######### CODE ############## # this is heavily based on # http://search.cpan.org/~geoff/Apache-Clean-2.00_7/

package Apache::Clean;
use 5.008;
use Apache2::Filter ();
use Apache2::RequestRec ();
use Apache2::RequestUtil ();
use Apache2::Log ();
use APR::Table ();
use Apache2::Const -compile => qw(OK DECLINED);
use strict;
sub handler {
my $f = shift;
my $r = $f->r;
my $log = $r->server->log;
unless ($r->content_type =~ m!text/html!i) {
$log->info('skipping request to ', $r->uri, ' (not an HTML document)');
return Apache2::DECLINED;
}
my $context;
unless ($f->ctx) {
$r->headers_out->unset('Content-Length');
}
$context ||= $f->ctx;
my $content_length = 0;
while ($f->read(my $buffer, 1024)) {
$buffer = $context->{extra} . $buffer if $context->{extra};
if (($context->{extra}) = $buffer =~ m/(<[^>]*)$/) {
$buffer = substr($buffer, 0, - length($context->{extra}));
}
my $str = $buffer;
$str =~ s,OLD,NEW,igs;
$content_length += length( $str );
$f->print( ${str} );
}
if ($f->seen_eos) {
$f->print($context->{extra}) if $context->{extra};
$content_length += length( $context->{extra} );
}
else {
$f->ctx($context);
}
$r->headers_out->set('Content-Length', $content_length);
$r->headers_out->set('Content-Length2', $content_length);
return Apache2::OK;
}
1;







######### HEADERS ##############

# no rev proxy
$ head localhost
200 OK
Connection: close
Date: Sat, 30 Apr 2005 20:02:17 GMT
Accept-Ranges: bytes
Server: Apache/2.0.54 (Win32) mod_ssl/2.0.53 OpenSSL/0.9.7f proxy_html/2.4 mod_perl/1.999.22-dev Perl/v5.8.6
Vary: negotiate,accept-language,accept-charset
Content-Language: en
Content-Length: 1773
Content-Location: index.html.en
Content-Type: text/html
Last-Modified: Sun, 21 Nov 2004 05:35:22 GMT
Client-Date: Sat, 30 Apr 2005 20:02:17 GMT
Client-Peer: 127.0.0.1:80
Client-Response-Num: 1
Content-Length2: 1773





# with rev proxy $ head localhost 200 OK Cache-Control: no-cache, no-store Connection: close Date: Sat, 30 Apr 2005 20:04:24 GMT Pragma: no-cache Server: Microsoft-IIS/6.0 Content-Type: text/html; charset=utf-8 Expires: -1 Client-Date: Sat, 30 Apr 2005 20:04:25 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 Content-Length2: 0 Set-Cookie: ASP.NET_SessionId=4nddnr453tjk0355flblp3fg; path=/ X-AspNet-Version: 1.1.4322 X-Powered-By: ASP.NET



Reply via email to