Small Engine/CGI.pm patch - was Re: [Catalyst-dev] Minimal test app for non-root deployment problem.

Jay K jayk at ion0.com
Thu Mar 8 02:14:41 GMT 2007


Took a bit of time to look into this and it is definitely a weird
scenario... it does expose some odd behavior - and what appears to be
a small buglet in Engine/CGI.pm - which I have attached a patch for.

Basically - if you use a non-root deployment, such as with '/fastcgi'
as your root, the web server will pass a request for just /fastcgi to
Catalyst as:

SCRIPT_NAME = '/fastcgi'
PATH_INFO = ''

Which is actually in accordance with the spec / etc., as far as I can
see.  The two main servers Cat is deployed against, lighttpd and
Apache, both behave the same in that respect.

Unfortunately, this confuses Catalyst because we expect to find at
least a / in the PATH_INFO environment var.

We actually take steps to make sure that we have at least a / in the
$base_path - but we do it after we have used $base_path once.

The fix is simply to move the 'make sure our base path ends in a
slash' code to before where it is used first (and before we create
our URI object)

Patch below.

Jay

--- snip ---

--- lib/Catalyst/Engine/CGI.pm.orig     Sat Nov  4 00:25:02 2006
+++ lib/Catalyst/Engine/CGI.pm  Wed Mar  7 19:50:53 2007
@@ -137,6 +137,10 @@
          $port = $c->request->secure ? 443 : 80;
      }

+    # set the base URI
+    # base must end in a slash
+    $base_path .= '/' unless ( $base_path =~ /\/$/ );
+
      my $path = $base_path . ( $ENV{PATH_INFO} || '' );
      $path =~ s{^/+}{};

@@ -151,9 +155,6 @@
      $uri = $uri->canonical;
      $c->request->uri($uri);

-    # set the base URI
-    # base must end in a slash
-    $base_path .= '/' unless ( $base_path =~ /\/$/ );
      my $base = $uri->clone;
      $base->path_query($base_path);
      $c->request->base($base);

--- snip ---

On Mar 7, 2007, at 7:06 PM, Kieren Diment wrote:

> Hi,
>
> I've attached a minimal test app for the deployment problem I've
> been having.
>
> the file run_tests.sh shows how the tests should be run.
>
> Everything is fine with the built in server and lighttpd deployed
> as root.  Because Apache::Test is a bit of a pig to work with I've
> only done a non-root harness for apache and the same test fails for
> both apache and lighttpd-non-root
>
> Firing up a browser for the external non-root servers shows me the
> same test failures as for the failing
> Test::WWW::Mechanize::Catalyst test.  For interactive use the
> details are a little more interesting:
>
> http://localhost:8529/fastcgi => default
> http://localhost:8529/fastcgi/ => index
> http://localhost:8529/fastcgi/x => default
>
>
> What should be the same request from Catalyst::Test passes, and
> this is what's making me think that there's a problem is at the
> catalyst end.  This also may explain why this bug has gone unnoticed.
>
> I've also added another controller beneath root (y/) and these
> tests pass on all deployment scenarios indicating that the problem
> seems to be only with the root controller.
>
>
>
> <NonRoot.tar.gz>
> _______________________________________________
> Catalyst-dev mailing list
> Catalyst-dev at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst-dev

---
America will never be destroyed from the outside. If we falter and
lose our freedoms, it will be because we destroyed ourselves. --
Abraham Lincoln





More information about the Catalyst-dev mailing list