Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Plack::Builder::Cascade?

Received: by 10.58.229.232 with SMTP id st8mr1854224vec.34.1349376052691;
        Thu, 04 Oct 2012 11:40:52 -0700 (PDT)
X-BeenThere: psgi-plack@googlegroups.com
Received: by 10.52.21.40 with SMTP id s8ls2592631vde.8.gmail; Thu, 04 Oct 2012
 11:40:51 -0700 (PDT)
Received: by 10.52.71.38 with SMTP id r6mr1256146vdu.12.1349376051622;
        Thu, 04 Oct 2012 11:40:51 -0700 (PDT)
Date: Thu, 4 Oct 2012 11:40:51 -0700 (PDT)
From: "jakob.v...@gbv.de" <jakob.v...@gbv.de>
To: psgi-plack@googlegroups.com
Message-Id: <05eb22e2-f0f0-48dc-9afb-bc5de62373e2@googlegroups.com>
Subject: Plack::Builder::Cascade?
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_81_30899426.1349376051146"

------=_Part_81_30899426.1349376051146
Content-Type: multipart/alternative; 
	boundary="----=_Part_82_23892186.1349376051150"

------=_Part_82_23892186.1349376051150
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

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

------=_Part_82_23892186.1349376051150
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi,<br><br>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:<br><br>builder {<br>&=
nbsp; cascade {<br>&nbsp;&nbsp;&nbsp;&nbsp; # first try basic authentificat=
ion<br>&nbsp;&nbsp;&nbsp;&nbsp; via "Auth::Basic", authentificator =3D&gt; =
\&amp;foo;<br>&nbsp;&nbsp;&nbsp;&nbsp; # otherwise look for access token<br=
>&nbsp;&nbsp;&nbsp;&nbsp; via "Auth::AccessToken", authentificator =3D&gt; =
\&amp;bar;<br>&nbsp;&nbsp;&nbsp;&nbsp; # if both fail, try some rules, for =
instance access from some IPs<br>&nbsp;&nbsp;&nbsp;&nbsp; via "Access", rul=
es =3D&gt; $rules;<br>&nbsp; };<br>&nbsp; # each of the middlewares above d=
elegates to this app<br>&nbsp; $app;<br>};<br><br>Depending on the type of =
cascade middleware, the underlying $app would be called multiple times, unt=
il 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 m=
ake sure to seek the input stream for each request path.<br><br>Am I missin=
g something are is there an easier solution to cascading middleware? This m=
ight work, but very ugly to type:<br><br>Plack::App::Cascade-&gt;new( apps =
=3D&gt; [<br>&nbsp;&nbsp;&nbsp; map { builder { enable @$_; $app } } (<br>&=
nbsp;&nbsp;&nbsp;&nbsp; Plack::Middleware::Auth::Basic-&gt;new( authentific=
ator =3D&gt; \&amp;foo ),<br>&nbsp;&nbsp;&nbsp;&nbsp; Plack::Middleware::Au=
th::AccessToken-&gt;new( authentificator =3D&gt; \&amp;bar ),<br>&nbsp;&nbs=
p;&nbsp;&nbsp; Plack::Middleware::Access-&gt;new( rules =3D&gt; $rules )<br=
>&nbsp;&nbsp;&nbsp; )<br>], codes =3D&gt; qw/^[45]/ );<br><br>Cheers,<br>Ja=
kob<br>
------=_Part_82_23892186.1349376051150--

------=_Part_81_30899426.1349376051146--