Rename router() to handler() in PSGI (#820)

This commit is contained in:
Xavier Guimard 2016-02-11 06:00:35 +00:00
parent e06c095bb1
commit 0f8fe7894f
10 changed files with 22 additions and 22 deletions

View File

@ -149,7 +149,7 @@ sub init {
return 1; return 1;
} }
sub router { _mustBeDefined(@_) } sub handler { _mustBeDefined(@_) }
sub sendHtml { sub sendHtml {
my ( $self, $req, $template ) = @_; my ( $self, $req, $template ) = @_;
@ -217,7 +217,7 @@ sub run {
sub _run { sub _run {
my $self = shift; my $self = shift;
return sub { return sub {
$self->router( Lemonldap::NG::Common::PSGI::Request->new( $_[0] ) ); $self->handler( Lemonldap::NG::Common::PSGI::Request->new( $_[0] ) );
}; };
} }
@ -251,7 +251,7 @@ Use Lemonldap::NG::Common::PSGI::Router for REST API.
return 1; return 1;
} }
sub router { sub handler {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
# Do something and return a PSGI response # Do something and return a PSGI response
# NB: $req is a Lemonldap::NG::Common::PSGI::Request object # NB: $req is a Lemonldap::NG::Common::PSGI::Request object

View File

@ -164,7 +164,7 @@ PSGIs
# See Lemonldap::NG::Common::PSGI # See Lemonldap::NG::Common::PSGI
... ...
sub router { sub handler {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
# Do something and return a PSGI response # Do something and return a PSGI response
# NB: $req is a Lemonldap::NG::Common::PSGI::Request object # NB: $req is a Lemonldap::NG::Common::PSGI::Request object

View File

@ -77,7 +77,7 @@ sub genRoute {
} }
} }
sub routerAbort { sub handlerAbort {
my ( $self, $path, $msg ) = @_; my ( $self, $path, $msg ) = @_;
delete $self->routes->{$path}; delete $self->routes->{$path};
$self->addRoute( $self->addRoute(
@ -90,7 +90,7 @@ sub routerAbort {
# Methods that dispatch requests # Methods that dispatch requests
sub router { sub handler {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
#print STDERR Dumper($self->routes);use Data::Dumper; #print STDERR Dumper($self->routes);use Data::Dumper;

View File

@ -34,7 +34,7 @@ sub _run {
}; };
} }
## @method PSGI-Response router() ## @method PSGI-Response handler()
# Transform headers returned by handler main process: # Transform headers returned by handler main process:
# each "Name: value" is transformed to: # each "Name: value" is transformed to:
# - Headername<i>: Name # - Headername<i>: Name
@ -55,7 +55,7 @@ sub _run {
# auth_request_set $llremoteuser $upstream_http_lm_remote_user # auth_request_set $llremoteuser $upstream_http_lm_remote_user
# #
#@param $req Lemonldap::NG::Common::PSGI::Request #@param $req Lemonldap::NG::Common::PSGI::Request
sub router { sub handler {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
my $hdrs = $req->{respHeaders}; my $hdrs = $req->{respHeaders};
$req->{respHeaders} = {}; $req->{respHeaders} = {};

View File

@ -38,7 +38,7 @@ Lemonldap::NG::Handler::PSGI - Base library for protected PSGI applications.
return 1; return 1;
} }
sub router { sub handler {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
# Will be called only if authorisated # Will be called only if authorisated

View File

@ -33,7 +33,7 @@ sub init {
## @methodi void _run() ## @methodi void _run()
# Check if protecton is activated then return a code ref that will launch # Check if protecton is activated then return a code ref that will launch
# _authAndTrace() if protection in on or router() else # _authAndTrace() if protection in on or handler() else
#@return code-ref #@return code-ref
sub _run { sub _run {
my $self = shift; my $self = shift;
@ -63,7 +63,7 @@ sub _run {
# Handle unprotected requests # Handle unprotected requests
return sub { return sub {
my $req = Lemonldap::NG::Common::PSGI::Request->new( $_[0] ); my $req = Lemonldap::NG::Common::PSGI::Request->new( $_[0] );
my $res = $self->router($req); my $res = $self->handler($req);
push @{ $res->[1] }, %{ $req->{respHeaders} }; push @{ $res->[1] }, %{ $req->{respHeaders} };
return $res; return $res;
}; };
@ -71,7 +71,7 @@ sub _run {
} }
## @method private PSGI-Response _authAndTrace($req) ## @method private PSGI-Response _authAndTrace($req)
# Launch Lemonldap::NG::Handler::SharedConf::run() and then router() if # Launch Lemonldap::NG::Handler::SharedConf::run() and then handler() if
# response is 200. # response is 200.
sub _authAndTrace { sub _authAndTrace {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
@ -80,8 +80,8 @@ sub _authAndTrace {
$req->userData($datas) if ($datas); $req->userData($datas) if ($datas);
if ( $res < 300 ) { if ( $res < 300 ) {
$self->lmLog( 'User authenticated, calling router()', 'debug' ); $self->lmLog( 'User authenticated, calling handler()', 'debug' );
return $self->router($req); return $self->handler($req);
} }
else { else {
my %h = $req->{respHeaders} ? %{ $req->{respHeaders} } : (); my %h = $req->{respHeaders} ? %{ $req->{respHeaders} } : ();

View File

@ -8,7 +8,7 @@ extends 'Lemonldap::NG::Handler::PSGI';
## @method void _run() ## @method void _run()
# Return subroutine that add headers stored in $req->{respHeaders} in # Return subroutine that add headers stored in $req->{respHeaders} in
# response returned by router() # response returned by handler()
# #
sub _run { sub _run {
my ($self) = @_; my ($self) = @_;
@ -20,12 +20,12 @@ sub _run {
}; };
} }
## @method PSGI-Response router($req) ## @method PSGI-Response handler($req)
# If PSGI is used as an authentication FastCGI only, this method will be # If PSGI is used as an authentication FastCGI only, this method will be
# called for authenticated users and returns only 200. Headers are set by # called for authenticated users and returns only 200. Headers are set by
# Lemonldap::NG::Handler::PSGI. # Lemonldap::NG::Handler::PSGI.
# @param $req Lemonldap::NG::Common::PSGI::Request # @param $req Lemonldap::NG::Common::PSGI::Request
sub router { sub handler {
return [ 200, [ 'Content-Length', 0 ], [] ]; return [ 200, [ 'Content-Length', 0 ], [] ];
} }

View File

@ -77,7 +77,7 @@ count(2);
done_testing( count() ); done_testing( count() );
sub Lemonldap::NG::Handler::PSGI::router { sub Lemonldap::NG::Handler::PSGI::handler {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
ok( $req->{HTTP_AUTH_USER} eq 'dwho', 'Header is given to app' ) ok( $req->{HTTP_AUTH_USER} eq 'dwho', 'Header is given to app' )
or explain( $req->{HTTP_REMOTE_USER}, 'dwho' ); or explain( $req->{HTTP_REMOTE_USER}, 'dwho' );

View File

@ -23,7 +23,7 @@ PSGI system launch the previous sub
sub sub
| |
+-> Common::PSGI::Router::router ( Lemonldap::NG::Common::PSGI::Request->new() ) +-> Common::PSGI::Router::handler ( Lemonldap::NG::Common::PSGI::Request->new() )
| |
+-> Common::PSGI::Router::followPath() +-> Common::PSGI::Router::followPath()
| |

View File

@ -87,7 +87,7 @@ sub notifAccess {
# TODO: old parameters (with table) # TODO: old parameters (with table)
unless ( $self->{notificationStorage} ) { unless ( $self->{notificationStorage} ) {
$self->routerAbort( notifications => $self->handlerAbort( notifications =>
'notificationStorage is not defined in configuration' ); 'notificationStorage is not defined in configuration' );
return 0; return 0;
} }
@ -102,7 +102,7 @@ sub notifAccess {
# If type not File or DBI, abort # If type not File or DBI, abort
unless ( $args->{type} =~ /^(File|DBI|LDAP)$/ ) { unless ( $args->{type} =~ /^(File|DBI|LDAP)$/ ) {
$self->routerAbort( notifications => $self->handlerAbort( notifications =>
"Only File, DBI or LDAP supported for Notifications" ); "Only File, DBI or LDAP supported for Notifications" );
return 0; return 0;
} }
@ -112,7 +112,7 @@ sub notifAccess {
unless ( unless (
$self->_notifAccess( Lemonldap::NG::Common::Notification->new($args) ) ) $self->_notifAccess( Lemonldap::NG::Common::Notification->new($args) ) )
{ {
$self->routerAbort( $self->handlerAbort(
notifications => $Lemonldap::NG::Common::Notification::msg ); notifications => $Lemonldap::NG::Common::Notification::msg );
return 0; return 0;
} }