perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@muly.dk
Subject Re: advice needed: mod_perl reverse proxy
Date Wed, 04 May 2005 12:29:10 GMT
hi i don't get it. the below filter does output the content alright it 
seems, but the setting of the header *value* is incorrect. (?)
so the $f->print statement prints correct output
but the calcualtion length(output) is incorrect (since it evaluates 
length of this exact string "<html><head></head><body></body></html>\n"

)
why is that and how to fix this ??

many thanks
./allan

# 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 configured

# this is the actual 11 bytes of content on URL:
# hello world

# $ get localhost
# hello world


# $ head localhost
# ...
# Server: Microsoft-IIS/6.0
# Content-Length: 40
# Content-Type: text/html; charset=utf-8
# ...


# excerpt of code
my $context;
unless ($f->ctx) {
	$r->headers_out->unset( "Content-Length" );
}

$context ||= $f->ctx;
my $content_length = 0;
my $str = "";

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}));
	}
	$str .= $buffer;
}

if ($f->seen_eos) {
	if ( $context->{extra} ) {
		$str .= $context->{extra};
	}
}

else {
	$f->ctx($context);
}



$str = Rewrite::replace_links ( $str );
# at this point $str equals: <html><head></head><body></body></html>

$content_length += length( $str );

# set header
$r->err_headers_out->set('Content-Length', $content_length );

$f->print( $str );
# at this point $str equals: all 42KB of correct html



Mime
View raw message