Re: advice needed: mod_perl reverse proxy

[prev] [thread] [next] [Date index for 2005/05/10]

From: allan
Subject: Re: advice needed: mod_perl reverse proxy
Date: 07:27 on 10 May 2005
Quoting Stas Bekman <stas@xxxxxx.xxx>:

> allan@xxxx.xx wrote:
>> Quoting Stas Bekman <stas@xxxxxx.xxx>:
>>
>>> allan juul wrote:
>>> [...]
>>>
>>>>> Use must use $r->set_content_length(). See the mp2 test suite for 
>>>>> examples.
>>>>
>>>>
>>>>
>>>> (i don't have that method available in my mod_perl2)
>>>
>>>
>>> You sure do :)
>>>
>>> % lookup set_content_length
>>> To use method 'set_content_length' add:
>>>         use Apache2::Response ();
>>> http://perl.apache.org/docs/2.0/api/Apache2/Response.html#C_set_content_length_
>>
>>
>> ok maybe i have a screwed installiation or a missing use/namespace . 
>> "method not found" message in my error.log.
>>
>>>> but about collecting data in a buffer variable. it seems i can 
>>>> actually $f->print that buffer, but not actually calculate the 
>>>> length of it. or rather: i can calculate the length but when i set 
>>>> any header the value is 0 (whether i set it before the $f->print 
>>>> statement or after).
>>>> it seems i must admit that i don't quite get what is going on and when.
>>>>
>>>> can anyone supply a simple example i then can check on our reverse proxy ?
>>>
>>>
>>> Try: t/response/TestApache/content_length_header.pm
>>> Though I haven't tried to call it from the filter, so may be Jeff's 
>>> suggestion will work.
>>
>>
>>
>> Jeff's suggestion does indeed work. oddly enough ;
>
> It just happens to work in certain conditions. The correct solution 
> is to use a bucket brigade-based filter, which gives you a complete 
> control. What's happening is that streaming filter API passes FLUSH 
> buckets through, and you can't control that. We have to do that to 
> conform to the FLUSH requests, to be a well-behaved filter by default.
> I've revealed that using 2 debug filters plugged before and after the 
> filter in question. This is a very useful debugging tool:
> http://search.cpan.org/dist/Apache-DebugFilter/

well its not available yet on win32.

> So the following solution works just fine, it'll be added shortly to 
> the mp2 test suite as a pair of tests: t/filter/out_str_buffer.t 
> t/filter/TestFilter/out_str_buffer.pm


thanks for the example andf replies. however, i get this error:

  Can't locate object method "first" via package "APR::Brigade" i have 
prior to that just uninstalled mod_perl [RC5] and installed mod_perl 
[RC6] via ppm (randys repository i beleve)


./allan



> and I'll document it too.
>
> sub flatten_bb {
>     my ($bb) = shift;
>
>     my $seen_eos = 0;
>
>     my @data;
>     for (my $b = $bb->first; $b; $b = $bb->next($b)) {
>         $seen_eos++, last if $b->is_eos;
>         $b->read(my $bdata);
>         push @data, $bdata;
>     }
>     return (join('', @data), $seen_eos);
> }
>
> sub handler {
>     my($filter, $bb) = @_;
>
>     my $ctx = $filter->ctx;
>
>     # no need to unset the C-L header, since this filter makes sure to
>     # correct it before any headers go out.
>     #unless ($ctx) {
>     #    $filter->r->headers_out->unset('Content-Length');
>     #}
>
>     my $data = exists $ctx->{data} ? $ctx->{data} : '';
>     $ctx->{invoked}++;
>     my($bdata, $seen_eos) = flatten_bb($bb);
>     $bdata =~ s/-//g;
>     $data .= $bdata if $bdata;
>
>     if ($seen_eos) {
>         my $len = length $data;
>         $filter->r->headers_out->set('Content-Length', $len);
>         $filter->print($data) if $data;
>     }
>     else {
>         # store context for all but the last invocation
>         $ctx->{data} = $data;
>         $filter->ctx($ctx);
>     }
>
>     return Apache2::Const::OK;
> }
>
>
> -- 
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
>



(message missing)

advice needed: mod_perl reverse proxy
allan juul 19:18 on 20 Apr 2005

Re: advice needed: mod_perl reverse proxy
Stas Bekman 20:24 on 20 Apr 2005

Re: advice needed: mod_perl reverse proxy
allan juul 20:53 on 20 Apr 2005

Re: advice needed: mod_perl reverse proxy
Stas Bekman 22:08 on 20 Apr 2005

Re: advice needed: mod_perl reverse proxy
allan juul 20:22 on 30 Apr 2005

compile mod_perl with Apache::DBI support
jiesheng zhang 05:07 on 02 May 2005

Re: compile mod_perl with Apache::DBI support
Stas Bekman 06:43 on 02 May 2005

Re: compile mod_perl with Apache::DBI support
jiesheng zhang 12:10 on 02 May 2005

Re: compile mod_perl with Apache::DBI support
Perrin Harkins 14:48 on 02 May 2005

Re: compile mod_perl with Apache::DBI support
jiesheng zhang 16:21 on 02 May 2005

Re: compile mod_perl with Apache::DBI support
Perrin Harkins 16:22 on 02 May 2005

Re: compile mod_perl with Apache::DBI support
jiesheng zhang 16:46 on 02 May 2005

Re: advice needed: mod_perl reverse proxy
Stas Bekman 06:48 on 02 May 2005

Re: advice needed: mod_perl reverse proxy
Devin Murphy 20:25 on 20 Apr 2005

Re: advice needed: mod_perl reverse proxy
Dominique Quatravaux 08:38 on 21 Apr 2005

Re: advice needed: mod_perl reverse proxy
Alex Greg 09:08 on 21 Apr 2005

Re: compile mod_perl with Apache::DBI support
Michael Peters 17:02 on 02 May 2005

Re: advice needed: mod_perl reverse proxy
allan juul 18:42 on 03 May 2005

Re: advice needed: mod_perl reverse proxy
Jeff Ambrosino 20:12 on 03 May 2005

Re: advice needed: mod_perl reverse proxy
Stas Bekman 22:40 on 03 May 2005

Re: advice needed: mod_perl reverse proxy
Stas Bekman 01:56 on 10 May 2005

Re: advice needed: mod_perl reverse proxy
allan 07:27 on 10 May 2005

Re: advice needed: mod_perl reverse proxy
Stas Bekman 16:43 on 10 May 2005

Re: advice needed: mod_perl reverse proxy
Stas Bekman 01:59 on 10 May 2005

Generated at 06:56 on 17 May 2005 by mariachi v0.52