[Catalyst] uri rewrite (drop port)

Krzysztof Krzyżaniak eloy at pawnhearts.eu.org
Tue Jun 27 23:32:39 CEST 2006


Armin Obersteiner <armin at xos.net> writes:

> From: Armin Obersteiner <armin at xos.net>
> Subject: uri rewrite (drop port)
> To: catalyst at lists.rawmode.org
> Date: Tue, 27 Jun 2006 23:02:21 +0200
>
> hi!
>
> I'd like to drop the port from the base/uri part:
>
> 'request' => bless( {
>   'base' => bless( do{\(my $o = 'http://www:3000/')}, 'URI::http' ),
>   'uri' => bless( do{\(my $o = 'http://www:3000/')}, 'URI::http' ),
>   ...
>
> Reason: I have an ip range and for each ip port 80 is redirected on my 
> firewall to some highport of an application server. For the outside user
> everything is port 80 and request should go there.
>
> Somehow Catalyst::Engine::HTTP adds :3000 (or any other port but 80)
> to the url. Understandable so far. But not usable in my case.
>
> I want to drop the port in the most Catalyst compatible way, but I definitely
> want/need to do it within Catalyst. (No proxy or rewrite engine beforehand.)
>
> Can I just overwrite the base/uri objects at an early stage of the
> request. When/how?
>
> I'm a catalyst newbie but read most of the documentation on cpan and
> searched the list. No real solution came up, but some $ENV mangling,
> this can't be it?

I've had the same problem. You have to overload uri_for method and use it 
for all links

Take look at:
<http://kofeina.net/websvn/filedetails.php?repname=SireCSM&path=%2FSireCSM%2Ftrunk%2Flib%2FSireCSM.pm&rev=0&sc=0>

sub uri_for 
{
     my $c = shift;
     my $uri = $c->NEXT::uri_for(@_);
         if ($c->config->{'remove_port'})
         {
                 $uri->port( $uri->default_port );       
         }
     $uri;
}

  eloy
-- 
-------e-l-o-y----------------------------e-l-o-y- at -k-o-f-e-i-n-a-.-n-e-t------

       jak to dobrze, że są oceany - bez nich byłoby jeszcze smutniej



More information about the Catalyst mailing list