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;
}
sub router { _mustBeDefined(@_) }
sub handler { _mustBeDefined(@_) }
sub sendHtml {
my ( $self, $req, $template ) = @_;
@ -217,7 +217,7 @@ sub run {
sub _run {
my $self = shift;
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;
}
sub router {
sub handler {
my ( $self, $req ) = @_;
# Do something and return a PSGI response
# NB: $req is a Lemonldap::NG::Common::PSGI::Request object

View File

@ -164,7 +164,7 @@ PSGIs
# See Lemonldap::NG::Common::PSGI
...
sub router {
sub handler {
my ( $self, $req ) = @_;
# Do something and return a PSGI response
# 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 ) = @_;
delete $self->routes->{$path};
$self->addRoute(
@ -90,7 +90,7 @@ sub routerAbort {
# Methods that dispatch requests
sub router {
sub handler {
my ( $self, $req ) = @_;
#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:
# each "Name: value" is transformed to:
# - Headername<i>: Name
@ -55,7 +55,7 @@ sub _run {
# auth_request_set $llremoteuser $upstream_http_lm_remote_user
#
#@param $req Lemonldap::NG::Common::PSGI::Request
sub router {
sub handler {
my ( $self, $req ) = @_;
my $hdrs = $req->{respHeaders};
$req->{respHeaders} = {};

View File

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

View File

@ -33,7 +33,7 @@ sub init {
## @methodi void _run()
# 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
sub _run {
my $self = shift;
@ -63,7 +63,7 @@ sub _run {
# Handle unprotected requests
return sub {
my $req = Lemonldap::NG::Common::PSGI::Request->new( $_[0] );
my $res = $self->router($req);
my $res = $self->handler($req);
push @{ $res->[1] }, %{ $req->{respHeaders} };
return $res;
};
@ -71,7 +71,7 @@ sub _run {
}
## @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.
sub _authAndTrace {
my ( $self, $req ) = @_;
@ -80,8 +80,8 @@ sub _authAndTrace {
$req->userData($datas) if ($datas);
if ( $res < 300 ) {
$self->lmLog( 'User authenticated, calling router()', 'debug' );
return $self->router($req);
$self->lmLog( 'User authenticated, calling handler()', 'debug' );
return $self->handler($req);
}
else {
my %h = $req->{respHeaders} ? %{ $req->{respHeaders} } : ();

View File

@ -8,7 +8,7 @@ extends 'Lemonldap::NG::Handler::PSGI';
## @method void _run()
# Return subroutine that add headers stored in $req->{respHeaders} in
# response returned by router()
# response returned by handler()
#
sub _run {
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
# called for authenticated users and returns only 200. Headers are set by
# Lemonldap::NG::Handler::PSGI.
# @param $req Lemonldap::NG::Common::PSGI::Request
sub router {
sub handler {
return [ 200, [ 'Content-Length', 0 ], [] ];
}

View File

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

View File

@ -23,7 +23,7 @@ PSGI system launch the previous 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()
|

View File

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