jakob...@gbv.de
unread,Oct 4, 2012, 2:40:51 PM10/4/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to psgi-...@googlegroups.com
Hi,
There is Plack::App::Cascade to query a list of apps, one after another, until a non-404 response is returned, but can you do the same with a middleware? I was looking for something like this:
builder {
cascade {
# first try basic authentification
via "Auth::Basic", authentificator => \&foo;
# otherwise look for access token
via "Auth::AccessToken", authentificator => \&bar;
# if both fail, try some rules, for instance access from some IPs
via "Access", rules => $rules;
};
# each of the middlewares above delegates to this app
$app;
};
Depending on the type of cascade middleware, the underlying $app would be called multiple times, until a non-error-response is returned. Could this be a problem, for instance when the request body has to be read again? The middleware cascade should make sure to seek the input stream for each request path.
Am I missing something are is there an easier solution to cascading middleware? This might work, but very ugly to type:
Plack::App::Cascade->new( apps => [
map { builder { enable @$_; $app } } (
Plack::Middleware::Auth::Basic->new( authentificator => \&foo ),
Plack::Middleware::Auth::AccessToken->new( authentificator => \&bar ),
Plack::Middleware::Access->new( rules => $rules )
)
], codes => qw/^[45]/ );
Cheers,
Jakob