From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.86.23.1 with SMTP id 1cs33372fgw; Thu, 10 Sep 2009 09:57:18 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.150.174.35 as permitted sender) client-ip=10.150.174.35; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.150.174.35 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.150.174.35]) by 10.150.174.35 with SMTP id w35mr5230827ybe.29.1252601837171 (num_hops = 1); Thu, 10 Sep 2009 09:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received:received-spf:received:dkim-signature :domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; bh=z60QGnvFJiNc+S6huhZJYoDnmmGYuOZOzNEbvGj3OuM=; b=HJ0moGxAe904itdKyV9krrJrYlAclJBalinBCA2/48l0VxHlShtzYlJX5YeWiIx6up 9s+gu+wKGEeJ9ZvxvDMXOeSbvRUf/rjIQeBWiQHpD5kUI8Y6LM6/5xRfhBdVgUVWcv7F 9YjVqjHYCesSW8hngcfwKW8TUIVQYY4FPtjy4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results :dkim-signature:domainkey-signature:mime-version:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; b=5JRSUtK4Tt6OOu7HZzNZliCoMWt0VXAcGcT7QM7kmRJhBOi9m/QM8JISRx5G4HoEZa p3IhnccY1q4m4bmPkh06jdzHGlBm6cXIZXAvk7se9jkwVhUKRbDL/5tkeXcOIW9/LWnR OCd5mib+8rptp951ye62mnPNSeaV7C7mWfuX4= Received: by 10.150.174.35 with SMTP id w35mr643628ybe.29.1252601837119; Thu, 10 Sep 2009 09:57:17 -0700 (PDT) Received: by 10.177.5.4 with SMTP id h4gr1655yqi.0; Thu, 10 Sep 2009 09:57:12 -0700 (PDT) X-Sender: judofyr@gmail.com X-Apparently-To: rack-devel@googlegroups.com Received: by 10.103.86.7 with SMTP id o7mr48525mul.1.1252601831543; Thu, 10 Sep 2009 09:57:11 -0700 (PDT) Received: by 10.103.86.7 with SMTP id o7mr48524mul.1.1252601831522; Thu, 10 Sep 2009 09:57:11 -0700 (PDT) Return-Path: Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com [209.85.218.224]) by gmr-mx.google.com with ESMTP id 14si236534bwz.5.2009.09.10.09.57.10; Thu, 10 Sep 2009 09:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of judofyr@gmail.com designates 209.85.218.224 as permitted sender) client-ip=209.85.218.224; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of judofyr@gmail.com designates 209.85.218.224 as permitted sender) smtp.mail=judofyr@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by bwz24 with SMTP id 24so240743bwz.38 for ; Thu, 10 Sep 2009 09:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=3YSplWEcuZpilsaJ8uiKvzArJ1KpLzOw0PL2szypA+U=; b=hg+r1HwtvYX/SFB6n5P66+af3UoeXQ6Qp3QHpj1RpIqkfvTOCPJciFPvmuiod8PVix uMbKl3JstOn0gmtkF6rJBwtOWu1yHTCFM+Pnh/ilUOubQ64DoT9UDXMZrr1+YEvUMWdK B7UtgbBKMnyzibrbFgGVwCINaYEmB8Sc7KjT0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=GVrIJeWx6trRq5KwDWq7dngJo/4oESr5QPYG7C5o8TAkgcUjAzogW42pfhVEYgB0yx HGuBlfx2yCkP4WyfJtuP7vE/RV6zTZIaXbGimeW7MZjt5e8/GZ/UcFiKLIl+8WZ0nCNz o5z99A0RS8LCsGCz5kawbwjV4UwTM9WBBqTn0= MIME-Version: 1.0 Received: by 10.103.37.25 with SMTP id p25mr976894muj.42.1252601830141; Thu, 10 Sep 2009 09:57:10 -0700 (PDT) In-Reply-To: References: From: Magnus Holm Date: Thu, 10 Sep 2009 18:56:50 +0200 Message-ID: <391a49da0909100956u4d0b32cex47dbf74e48560c12@mail.gmail.com> Subject: Re: How to use common code in each "map" To: rack-devel@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com It is possible with a middleware: class Restricter def initialize(app, headers =3D {}) @app =3D app @headers =3D headers end def call(env) @headers.each do |key, value| unless env[key] =3D=3D value return [403, {}, ['Something']] end end @app.call(env) end end map "/service1" do use Restricter, "SERVER_NAME" =3D> "testing" run App1 end //Magnus Holm On Thu, Sep 10, 2009 at 17:53, I=C3=B1aki Baz Castillo wrote= : > > Hi, I'm trying to use common HTTP request validation code =C2=A0in each "= map" block: > > ---------------------------------------------------------------------- > Rack::Builder.new do > > =C2=A0map "/" do > =C2=A0 =C2=A0run Proc.new { |env| [ 404, {"Content-Type" =3D> "text/plain= "}, [""] ] } > =C2=A0end > > =C2=A0map "/service1" do > =C2=A0 =C2=A0___VALIDATION_CODE___ > =C2=A0 =C2=A0run MyApp1 > =C2=A0end > > =C2=A0map "/service2" do > =C2=A0 =C2=A0___VALIDATION_CODE___ > =C2=A0 =C2=A0run MyApp2 > =C2=A0end > > end > ---------------------------------------------------------------------- > > > Unfortunatelly I don't know how to fill ___VALIDATION_CODE___. > There I want to inspect env["SERVER_NAME"] and some other headers. In > case the validation is not passed, it should, *by itself*, return 403 > code and MyApp1 or MyApp2 execution shouldn't take place. > > IMHO it means that it cannot be done with a middleware since it would > execute MyApp1 or MyApp2. > > Which is the appropriate approach to achieve it? Thanks for any help. Reg= ards. > > > -- > I=C3=B1aki Baz Castillo > >