Subject: | CGI::Application::Dispatch::PSGI does not set HTTP_REQUEST in environment. |
When using CGI::Application::Dispatch::PSGI as per the example in
CGI::Application::Demo::Dispatch, with Starman, it fails to work when the dispatch routes
have HTTP method qualifiers.
For example, the code looks like this:
my($app) = CGI::Application::Dispatch -> as_psgi
(
prefix => 'CGI::Application::Demo::Dispatch',
table =>
[
'' => {app => 'Menu', rm => 'display'},
':app' => {rm => 'initialize'},
':app/:rm' => {},
],
);
If this is changed to:
my($app) = CGI::Application::Dispatch -> as_psgi
(
prefix => 'CGI::Application::Demo::Dispatch',
table =>
[
'' => {app => 'Menu', rm => 'display'},
':app[get]' => {rm => 'initialize'}, #NOTE THE METHOD
':app/:rm' => {},
],
);
This will fail, as CGI::Application::Dispatch will complain that on line 400 it failed to append a
string:
$rm .= "_$http_method";
because it failed to get the $http_method:
my $http_method = $self->_http_method;
Because that sub is as follows:
sub _http_method {
IS_MODPERL ? shift->_r->method : ($ENV{HTTP_REQUEST_METHOD} ||
$ENV{REQUEST_METHOD});
}
and unfortunately, the as_psgi method does not set either HTTP_REQUEST_METHOD or
REQUEST_METHOD in %ENV. I believe the attached patch will do what is needed.
Subject: | fix-psgi-not-setting-request-method.diff |
--- PSGI.pm.orig 2011-04-04 17:21:08.000000000 -0500
+++ PSGI.pm 2011-04-04 17:32:46.000000000 -0500
@@ -77,6 +77,8 @@
$args{args_to_new}->{QUERY} = CGI::PSGI->new($env);
local $ENV{PATH_INFO} = $env->{PATH_INFO};
+ local $ENV{REQUEST_METHOD} = $env->{REQUEST_METHOD};
+ local $ENV{HTTP_REQUEST_METHOD} = $env->{HTTP_REQUEST_METHOD};
$self->dispatch(%args);
};