Hi,

I am trying to implement a cache of currency foreign exchange from my 
application  and proxy the request to another server if I don't already 
have it in cache.

The code looks like:

sub getrate {
   my ($request,$env) = @_;
   my $response = Plack::Response->new(400,
                     [ 'Content-Type' => 'text/plain; charset=utf-8'],
                     [ 'Bad Parameters' ]
   );
   my $date = $request->{date};
   if ( $date && $date->is_date) {
       # Get buy rate
       my ($fxrate) = $request->call_procedure(
                       funcname => 'currency_get_exchangerate',
                       args => [$request->{curr},$date,2]);
       if ( $fxrate->{currency_get_exchangerate} ) {
           $response->status(200);
           $response->body([$fxrate->{currency_get_exchangerate}]);
       } else {
           my $url = '/getrate'
                    . '/' . $date->to_output('yyyy-mm-dd')
                   . '/' . $request->{curr}
                   . '/CAD';
           $env->{'plack.proxy.url'} = 
'http://currencies.apps.grandtrunk.net'
                                     . $url;
           return Plack::App::Proxy->new->to_app->($env);
       }
   }
   $response->finalize;
}

Now the regular portion works well, but Proxy handling results in a stack 
dump from Plack routines:
Status code needs to be an integer greater than or equal to 100:  at 
/usr/local/share/perl/5.22.2/Plack/Middleware/Lint.pm line 116
in Plack::Middleware::Lint::validate_res at 
/usr/local/share/perl/5.22.2/Plack/Middleware/Lint.pm line 116
in Plack::Middleware::Lint::call at 
/usr/local/share/perl/5.22.2/Plack/Middleware/Lint.pm line 25
in Plack::Middleware::StackTrace::try {...} at 
/usr/local/share/perl/5.22.2/Plack/Component.pm line 50
in (eval) at /usr/share/perl5/Try/Tiny.pm line 101
in Plack::Middleware::StackTrace::call at /usr/share/perl5/Try/Tiny.pm line 
94
in Plack::Component::__ANON__ at 
/usr/local/share/perl/5.22.2/Plack/Component.pm line 50
in Plack::Middleware::AccessLog::call at 
/usr/local/share/perl/5.22.2/Plack/Middleware/AccessLog.pm line 27
in Plack::Component::__ANON__ at 
/usr/local/share/perl/5.22.2/Plack/Component.pm line 50
in Plack::Middleware::ContentLength::call at 
/usr/local/share/perl/5.22.2/Plack/Middleware/ContentLength.pm line 10
in Plack::Component::__ANON__ at 
/usr/local/share/perl/5.22.2/Plack/Component.pm line 50
in (eval) at /usr/local/share/perl/5.22.2/Plack/Util.pm line 145
in Plack::Util::run_app at /usr/local/share/perl/5.22.2/Plack/Util.pm line 
145
in HTTP::Server::PSGI::handle_connection at 
/usr/local/share/perl/5.22.2/HTTP/Server/PSGI.pm line 170
in HTTP::Server::PSGI::accept_loop at 
/usr/local/share/perl/5.22.2/HTTP/Server/PSGI.pm line 129
in HTTP::Server::PSGI::run at 
/usr/local/share/perl/5.22.2/HTTP/Server/PSGI.pm line 55
in Plack::Handler::HTTP::Server::PSGI::run at 
/usr/local/share/perl/5.22.2/Plack/Handler/HTTP/Server/PSGI.pm line 14
in Plack::Loader::Restarter::_fork_and_start at 
/usr/local/share/perl/5.22.2/Plack/Loader/Restarter.pm line 32
in Plack::Loader::Restarter::run at 
/usr/local/share/perl/5.22.2/Plack/Loader/Restarter.pm line 89
in Plack::Runner::run at /usr/local/share/perl/5.22.2/Plack/Runner.pm line 
277
at /usr/bin/plackup line 10

Can anyone show me what am I doing wrong?

Thanks,

Yves

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"psgi-plack" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to psgi-plack+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to