Skip Menu |

This queue is for tickets about the CGI-Application-Dispatch CPAN distribution.

Report information
The Basics
Id: 25297
Status: resolved
Priority: 0/
Queue: CGI-Application-Dispatch

People
Owner: Nobody in particular
Requestors: cpan [...] punch.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.10
Fixed in: (no value)



Subject: _http_method uses wrong environment variable
Under cgi, sub _http_method uses HTTP_REQUEST_METHOD to determine the request method for dispatching under auto_rest. My apache uses REQUEST_METHOD for the request method. The attached patch updates Dispatch.pm to support REQUEST_METHOD. It also adds two tests to check that the logic works.
Subject: CGI-Application-Dispatch-2.10.REQUEST_METHOD.diff
diff -Naur CGI-Application-Dispatch-2.10.orig/lib/CGI/Application/Dispatch.pm CGI-Application-Dispatch-2.10/lib/CGI/Application/Dispatch.pm --- CGI-Application-Dispatch-2.10.orig/lib/CGI/Application/Dispatch.pm 2007-01-15 06:03:05.000000000 -0800 +++ CGI-Application-Dispatch-2.10/lib/CGI/Application/Dispatch.pm 2007-03-06 00:45:19.000000000 -0800 @@ -543,7 +543,12 @@ return; } -sub _http_method { IS_MODPERL ? shift->_r->method : $ENV{HTTP_REQUEST_METHOD}; } +sub _http_method { + my $self = shift; + return $self->_r->method if IS_MODPERL; + return $ENV{HTTP_REQUEST_METHOD} if $ENV{HTTP_REQUEST_METHOD}; + return $ENV{REQUEST_METHOD} if $ENV{REQUEST_METHOD}; +} sub _r { IS_MODPERL2 ? Apache2::RequestUtil->request : Apache->request; } diff -Naur CGI-Application-Dispatch-2.10.orig/t/cgi.t CGI-Application-Dispatch-2.10/t/cgi.t --- CGI-Application-Dispatch-2.10.orig/t/cgi.t 2007-01-15 06:03:05.000000000 -0800 +++ CGI-Application-Dispatch-2.10/t/cgi.t 2007-03-06 00:51:05.000000000 -0800 @@ -4,7 +4,7 @@ use strict; use warnings; use lib 't/lib'; -plan(tests => 27); +plan(tests => 29); # 1..5 # make sure we can get to our modules @@ -208,6 +208,45 @@ like_string($output, qr/404 not found/i, "proper 404 error is returned when PATH_INFO isn't parsed."); } +# 28 +# auto_rest with $ENV{HTTP_REQUEST_METHOD} +{ + local $ENV{PATH_INFO} = '/module_name/local_args_to_new'; + local $ENV{HTTP_REQUEST_METHOD} = 'GET'; + $output = CGI::Application::Dispatch->dispatch( + auto_rest => 1, + prefix => 'MyApp', + table => [ + ':app/:rm' => { + args_to_new => { + TMPL_PATH => 'events', + }, + }, + ], + + ); + contains_string($output, 'events', 'cgi auto rest with HTTP_REQUEST_METHOD'); +} + +# 29 +# auto_rest with $ENV{REQUEST_METHOD} +{ + local $ENV{PATH_INFO} = '/module_name/local_args_to_new'; + local $ENV{REQUEST_METHOD} = 'GET'; + $output = CGI::Application::Dispatch->dispatch( + auto_rest => 1, + prefix => 'MyApp', + table => [ + ':app/:rm' => { + args_to_new => { + TMPL_PATH => 'events', + }, + }, + ], + ); + contains_string($output, 'events', 'cgi auto rest with REQUEST_METHOD'); +} + # restore STDERR { close STDERR; diff -Naur CGI-Application-Dispatch-2.10.orig/t/lib/MyApp/Module/Name.pm CGI-Application-Dispatch-2.10/t/lib/MyApp/Module/Name.pm --- CGI-Application-Dispatch-2.10.orig/t/lib/MyApp/Module/Name.pm 2007-01-15 06:03:05.000000000 -0800 +++ CGI-Application-Dispatch-2.10/t/lib/MyApp/Module/Name.pm 2007-03-06 00:54:51.000000000 -0800 @@ -11,6 +11,7 @@ rm4 rm5 local_args_to_new + local_args_to_new_GET /]); } @@ -58,5 +59,9 @@ return $self->tmpl_path; } +sub local_args_to_new_GET { + my $self = shift; + return $self->tmpl_path; +} 1;
fixed in the upcoming 2.11