perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoffrey Young <>
Subject Re: Getting Content-Length of response after PerlRun
Date Wed, 31 May 2006 18:39:39 GMT wrote:
> Hi,
> I've researched around a lot but don't see a way to do this, if someone
> could enlighten me I'd greatly appreciate it!
> In a nutshell, I'm running some cgis through PerlRun, and when the cgi has
> finished and created the response, I want to get the length of that
> response and set a Content-Length header.
> My problem is I don't see anyway to get the length of the generated
> response via the api or modules.

the real problem is that you think you can do something that you really
can't.  the proper way to do C-L with CGI scripts (PerlRun or otherwise)
is to pre-calculate the C-L, set the header, then print your content.
what you want to do really can't be done - the CGI script is printing
right down the wire, which is after the C-L header has been sent, so
even if you could retrieve it it would be too late to do anything with.

if you want to be _really_ wacky, you could try leveraging something
like this

essentially, you'd need to alter the PRINT() routine to hold on to
everything that passes through it, including the headers.  then on
DESTROY() or something you could calculate the length of the data and
send along your held headers + the C-L header.

sounds like a lot of work, right?  easier: in your CGI script buffer
your own data, then print your own C-L header, followed by your data.

> Seems like I should be able to run it through another Content Generation
> stage handler, get the length and set the header, ..but I don't see a way
> to do this.

not with apache 1.3.  now if you were using apache 2.X then you could do
that... of course with 2.X you don't ever need to worry about the C-L
header anyway, since apache calculates it for you...

> I should add I'm actually using Zeus implementation of mod_perl but if
> there's a way to do this via  normal mod_perl 1.x I can adjust
> accordingly. It doesn't have support for the more esoteric mod_perl
> capabilities, but all the normal things.
> thank you very much!



View raw message