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 Params in Before filter

Received: by 10.204.33.19 with SMTP id f19mr1260668bkd.16.1294144013061;
        Tue, 04 Jan 2011 04:26:53 -0800 (PST)
X-BeenThere: sinatrarb@googlegroups.com
Received: by 10.204.32.79 with SMTP id b15ls6409035bkd.0.p; Tue, 04 Jan 2011
 04:26:49 -0800 (PST)
Received: by 10.204.7.7 with SMTP id b7mr1335633bkb.0.1294144009753;
        Tue, 04 Jan 2011 04:26:49 -0800 (PST)
Received: by 10.204.7.7 with SMTP id b7mr1335632bkb.0.1294144009713;
        Tue, 04 Jan 2011 04:26:49 -0800 (PST)
Return-Path: <k.ha...@finn.de>
Received: from mail-fx0-f41.google.com (mail-fx0-f41.google.com [209.85.161.41])
        by gmr-mx.google.com with ESMTP id dd11si4002475bkb.4.2011.01.04.04.26.49;
        Tue, 04 Jan 2011 04:26:49 -0800 (PST)
Received-SPF: neutral (google.com: 209.85.161.41 is neither permitted nor denied by best guess record for domain of k.ha...@finn.de) client-ip=209.85.161.41;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 209.85.161.41 is neither permitted nor denied by best guess record for domain of k.ha...@finn.de) smtp.mail=k.ha...@finn.de
Received: by mail-fx0-f41.google.com with SMTP id 12so7434975fxm.0
        for <sinatrarb@googlegroups.com>; Tue, 04 Jan 2011 04:26:49 -0800 (PST)
Received: by 10.223.103.8 with SMTP id i8mr1774509fao.47.1294144009377;
        Tue, 04 Jan 2011 04:26:49 -0800 (PST)
Return-Path: <k.ha...@finn.de>
Received: from [172.16.22.105] ([141.89.226.149])
        by mx.google.com with ESMTPS id b7sm2172806faa.18.2011.01.04.04.26.47
        (version=TLSv1/SSLv3 cipher=RC4-MD5);
        Tue, 04 Jan 2011 04:26:48 -0800 (PST)
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Apple Message framework v1081)
Subject: Re: Params in Before filter
From: Konstantin Haase <k.ha...@finn.de>
In-Reply-To: <cea8dbde-587a-428b-b5f5-9593e72a1633@j29g2000yqm.googlegroups.com>
Date: Tue, 4 Jan 2011 13:26:46 +0100
Content-Transfer-Encoding: quoted-printable
Message-Id: <0D8937D1-EA4B-4A71-9DD9-087F68215DBB@finn.de>
References: <cea8dbde-587a-428b-b5f5-9593e72a1633@j29g2000yqm.googlegroups.com>
To: sinatrarb@googlegroups.com
X-Mailer: Apple Mail (2.1081)

It took me some time to understand what you think the issue is.

The main  issue is the concept behind Sinatra routing. You do not have =
one true params hash but different versions of that hash depending on =
the handler you're in.

This is how I see Sinatra routing: Prepare request, run a couple of =
handlers, generate response. Each handler has its own params hash, =
access to all helper methods and can set the response with methods like =
body or halt. There are special handlers that can also set the response =
with its return value (route handlers, error handlers), but otherwise =
handlers all have the same options available and only are different in =
when they are triggered. An incoming request is "falling" through this =
handlers, similar to a petri net, and triggered handlers have tools =
available to change the course the request takes (pass, modifying the =
request, etc). This is unique to Sinatra and no other Rack router I know =
of works that way, not even the Padrino router.

Therefore path patterns, like conditions, are criteria for triggering =
the specific handlers, passing those upfront would not only not fit this =
basic principal, but would also be a major performance impact. All =
incoming requests would have to be matched against all route handlers, =
the routing best case would be worse than the current worst case, since =
we would also have to check if the request patch changed after each =
handler and would have to reroute again. We would have to completely =
change the way we handle params, and all that without a use case. Or at =
least I'm not aware of one.

Konstantin

On Jan 4, 2011, at 04:25 , Matt Todd wrote:

> I recently was "troubled" with upgrading an older Sinatra app to a
> newer version that doesn't include route params in filters. I'd known
> about this "bug" but hadn't taken the time to address it until now.
>=20
> I found this old conversation that addressed my question: =
http://bit.ly/fOFwMC
> (Linking because I don't know if Google will relate these
> conversations since I'm not replying directly.)
>=20
> However, it doesn't answer if this SHOULD be the case or if it's just
> an unintended consequence of when the routing happens in relation to
> the filters.
>=20
> Obviously, having `pass` essentially say "this route is incorrect"
> makes this a little less trivial since it's unclear as to whether we
> should rerun the filters or not if we did perform routing before the
> filters. I am still not sure it makes more sense to duplicate routing
> patterns and explicit param extraction in the filtering, though.
>=20
> Is there an openly discussed opinion or decision somewhere that says
> that this is how it should be?
>=20
> Wrote a quick failing spec to make sure I wasn't crazy:
> https://gist.github.com/764340
>=20
> If anything perhaps we should add a spec that says "route params are
> NOT available in filters"? Make it part of the spec?
>=20
> Cheers,
> Matt
>=20
> --=20
> You received this message because you are subscribed to the Google =
Groups "sinatrarb" group.
> To post to this group, send email to sinatrarb@googlegroups.com.
> To unsubscribe from this group, send email to =
sinatrarb+unsubscribe@googlegroups.com.
> For more options, visit this group at =
http://groups.google.com/group/sinatrarb?hl=3Den.
>=20