[Dancer-users] params for post route not working

GJ gj at freeshell.org
Tue Feb 21 05:44:46 CET 2012


On Mon, Feb 20, 2012 at 10:54:04AM +0000, David Precious wrote:
> > Hi all,
> > 
> > I am using Dancer 1.3092 .  I can't access or use params for post
> > routes, eg
> > 
> > ----
> > post '/login' => sub {
> >     # Validate the username and password they supplied
> >     if (params->{user} eq 'bob' && params->{pass} eq 'a') {
> >         session user => params->{user};
> >         redirect params->{path} || '/';
> >     } else {
> >         redirect '/login?failed=1';
> >     }
> > };
> > ----
> > 
> > The above example is from the documentation, the result is the `else'
> > redirection. I tried my own code also.  params->user is empty, in
> > fact if I dump all `params' its empty.  
> 
> Interesting.  Can you dump the request object returned by the
> 'request' keyword so we can see what Dancer got?

I accidentally replied to earlier to David only instead of the list.  As I
said earlier, this is the result of dumping the request object whilst running
under Apache -- my intended production environment. 

BTW, you may see some non-Dancer cookie stuff in there; that is because I'm
porting my authentication scheme from the old cgi setup in stages.  I don't
think it is necessarily causally related to the emptiness because POSTed
params don't work at all right now.

Regards,
GJ

----

$VAR1 = bless( {
                 '_read_position' => 0,
                 'content_length' => '27',
                 'connection' => 'keep-alive',
                 'headers' => bless( {
                                       'user-agent' => 'Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1',
                                       'connection' => 'keep-alive',
                                       'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                                       'accept-language' => 'en-us,en;q=0.5',
                                       'cookie' => 'session=5aa3a19de3fdd444d66a0ff1a799cc721a0d72a0; user_name=admin; dancer.session=empty',
                                       'accept-encoding' => 'gzip, deflate',
                                       'content-length' => '27',
                                       'host' => 'localhost',
                                       'accept-charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                                       'content-type' => 'application/x-www-form-urlencoded',
                                       'referer' => 'http://localhost/login'
                                     }, 'HTTP::Headers' ),
                 '_http_body' => bless( {
                                          'content_length' => '27',
                                          'tmpdir' => '/tmp',
                                          'buffer' => '',
                                          'state' => 'buffering',
                                          'chunk_buffer' => '',
                                          'body' => undef,
                                          'content_type' => 'application/x-www-form-urlencoded',
                                          'length' => 0,
                                          'chunked' => '',
                                          'upload' => {},
                                          'param_order' => [],
                                          'param' => {},
                                          'cleanup' => 1
                                        }, 'HTTP::Body::UrlEncoded' ),
                 '_route_pattern' => '/login',
                 'accept_encoding' => 'gzip, deflate',
                 '_route_params' => {},
                 'is_forward' => 0,
                 'uploads' => {},
                 '_body_params' => $VAR1->{'_http_body'}{'param'},
                 'body' => '',
                 'accept_charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                 'method' => 'POST',
                 'id' => 1,
                 'referer' => 'http://localhost/login',
                 'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                 'accept_type' => undef,
                 'env' => {
                            'psgi.multiprocess' => 1,
                            'SCRIPT_NAME' => '',
                            'PATH_INFO' => '/login',
                            'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                            'REQUEST_METHOD' => 'POST',
                            'psgi.multithread' => 0,
                            'SCRIPT_FILENAME' => '/home/gj/My-App/public/dispatch.cgi',
                            'SERVER_SOFTWARE' => 'Apache/2.2.14 (Ubuntu)',
                            'PLACK_ENV' => 'development',
                            'HTTP_USER_AGENT' => 'Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1',
                            'REMOTE_PORT' => '51328',
                            'QUERY_STRING' => '',
                            'SERVER_SIGNATURE' => '<address>Apache/2.2.14 (Ubuntu) Server at localhost Port 80</address>
',
                            'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
                            'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
                            'DANCER_APPDIR' => '/home/gj/My-App/bin/..',
                            'psgi.streaming' => 1,
                            'PATH' => '/usr/local/bin:/usr/bin:/bin',
                            'GATEWAY_INTERFACE' => 'CGI/1.1',
                            'psgi.version' => [
                                                1,
                                                1
                                              ],
                            'SCRIPT_URL' => '/login',
                            'DOCUMENT_ROOT' => '/home/gj/My-App/public',
                            'psgi.run_once' => 1,
                            'PATH_TRANSLATED' => '/home/gj/My-App/public/dispatch.cgi/login',
                            'SERVER_NAME' => 'localhost',
                            'HTTP_REFERER' => 'http://localhost/login',
                            'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
                            'SERVER_ADMIN' => 'you at example.com',
                            'HTTP_CONNECTION' => 'keep-alive',
                            'SCRIPT_URI' => 'http://localhost/login',
                            'CONTENT_LENGTH' => '27',
                            'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                            'SERVER_PORT' => '80',
                            'HTTP_COOKIE' => 'session=5aa3a19de3fdd444d66a0ff1a799cc721a0d72a0; user_name=admin; dancer.session=empty',
                            'REMOTE_ADDR' => '127.0.0.1',
                            'SERVER_PROTOCOL' => 'HTTP/1.1',
                            'psgi.errors' => *::STDERR,
                            'REQUEST_URI' => '/login',
                            'psgi.nonblocking' => 1,
                            'SERVER_ADDR' => '127.0.0.1',
                            'psgi.url_scheme' => 'http',
                            'HTTP_HOST' => 'localhost',
                            'psgi.input' => *::STDIN
                          },
                 'user_agent' => 'Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1',
                 'x_requested_with' => undef,
                 'path' => '/login',
                 'path_info' => '/login',
                 'accept_language' => 'en-us,en;q=0.5',
                 '_chunk_size' => 4096,
                 '_query_params' => {},
                 'host' => 'localhost',
                 'ajax' => 0,
                 'params' => {},
                 'content_type' => 'application/x-www-form-urlencoded',
                 'keep_alive' => undef
               }, 'Dancer::Request' );



More information about the Dancer-users mailing list