4 posts tagged “catalyst”
Hello again. Long time no see, but I'm fine.
I'm now working on こえ部 which is a voice communication service build with Catalyst.
It already has lots of funny voices. This is my recent favorite こえ(voice):
It's very funny, isn't it? :)
Let's sign up and enjoy it if you're interested in!
Lighttpd has error-handler-404 feature which is useful as dynamic content handler.
But it seems that Catalyst does not support this.
This is problem of Catalyst's environment parser (Catalyst::Engine::CGI)
When I set error-handler-404 to "/script/myapp_fastcgi.pl" and request /foo/bar (no exsits path),
Lighttpd call /script/myapp_fastcgi.pl with following %ENV
PATH_INFO and QUERY_STRING are always empty via error-handler-404.REQUEST_URI: /foo/bar
REDIRECT_URI: /script/myapp_fastcgi.pl
PATH_INFO: ''
QUERY_STRING: ''
Instead of those vars, set REQUEST_URI (path+query)
It seems that Lighttpd always set REQUEST_URI whether error-handler is set or not.
So the solution about this problem is that Engine::CGI parses REQUEST_URI for any lighttpd's request.
Here is the patch:
Update at 2006-09-09 14:36 +0900: updated patch--- /usr/local/share/perl/5.8.8/Catalyst/Engine/CGI.pm 2006-07-20 06:45:16.000000000 +0900
+++ lib/Catalyst/Engine/CGI.pm 2006-09-09 20:07:45.000000000 +0900
@@ -140,12 +140,28 @@
my $path = $base_path . ( $ENV{PATH_INFO} || '' );
$path =~ s{^/+}{};- my $uri = URI->new;
- $uri->scheme($scheme);
- $uri->host($host);
- $uri->port($port);
- $uri->path($path);
- $uri->query( $ENV{QUERY_STRING} ) if $ENV{QUERY_STRING};
+ my $uri;
+
+ # lighttpd always set requested uri into REQUEST_URI
+ if ( ( $ENV{SERVER_SOFTWARE} || '' ) =~ /lighttpd/ and $ENV{REQUEST_URI} ) {
+ $uri = URI->new( $ENV{REQUEST_URI} );
+ $uri->scheme($scheme);
+ $uri->host($host);
+ $uri->port($port);
+
+ use YAML;
+ warn Dump $uri;
+
+ $ENV{QUERY_STRING} = $uri->query if $uri->query;
+ }
+ else {
+ $uri = URI->new;
+ $uri->scheme($scheme);
+ $uri->host($host);
+ $uri->port($port);
+ $uri->path($path);
+ $uri->query( $ENV{QUERY_STRING} ) if $ENV{QUERY_STRING};
+ }# sanitize the URI
$uri = $uri->canonical;
@@ -167,7 +183,11 @@
my ( $self, $c ) = @_;
local (*ENV) = $self->env || \%ENV;- if ( $ENV{QUERY_STRING} ) {
+ if ( ( $ENV{SERVER_SOFTWARE} || '' ) =~ /lighttpd/ and $ENV{REQUEST_URI} ) {
+ my ($query_string) = $ENV{REQUEST_URI} =~ /\?(.*)/;
+ $self->SUPER::prepare_query_parameters( $c, $query_string );
+ }
+ elsif ( $ENV{QUERY_STRING} ) {
$self->SUPER::prepare_query_parameters( $c, $ENV{QUERY_STRING} );
}
}
Update at 2006-09-09 20:13 +0900: updated patch again, added prepare_query_parameters fixes for query_parameters.
nothingmuch gave me some ideas to Helper::Lighttpd:
- Static files generation (lighttpd.conf ...etc)
- Independent from Static::Simple for static files serving
Hmm, I thought this helper just as a test server, but these features exactly nice if it'll be implemented.
So I'm going to work for it.
And.. code patch is very welcome :)
Catalyst's default build-in test server has many problems now. (IE redirection, performance, and etc..)
So I've created Catalyst::Helper::Lighttpd today.
This is a helper script to generate a server script that makes lighttpd as a catalyst test server.
After install this module, you can generate new lighty's test server by following command:
Then ./script/myapp_lighttpd.pl are created../script/myapp_create.pl Lighttpd
Usage of this myapp_lighttpd.pl is:
Usage:
myapp_lighttpd.pl [options]Options:
-? -help display this help and exits
-host host (defaults to all)
-p -port port (defaults to 3000)
-l -lighttpd lighttpd path (defaults to `which lighttpd`)
Almost same as myapp_server.pl (default server).
But if your lighttpd comamnd is not in PATH environment, you need to specify it by -l option.
Actually this script just boot lighttpd as no daemon mode, and the server boot myapp_fastcgi.pl internal.
Very simple, but useful (for me :)
Although I'm going to upload this helper to CPAN, but I hope that default build-in server would have this feature if it possible.
catalyst gurus: How about this? Or any ideas?