rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
* Using Rack Middlware to filter parameters
@ 2009-11-05 11:02 RobL
  2009-11-05 22:32 ` Iñaki Baz Castillo
  0 siblings, 1 reply; 3+ messages in thread
From: RobL @ 2009-11-05 11:02 UTC (permalink / raw)
  To: Rack Development


Hi there,

I wanted to ask if anyone could point me in the direction of some code
examples where you can use Rack Middleware to filter incoming
parameters.

Of course the classic example of middleware that does not a lot is

module Rack
  class Myfilter
    def initialize(app)
      @app = app
    end

    def call(env)
       @app.call(env)
    end
  end
end

But as a very tivial example I want be able to do something like

module Rack
  class Myfilter
    def initialize(app)
      @app = app
    end

    def call(env)
       request = Rack::Request.new(env)
       request.params.delete('someparam')
       # but at this point I want/need to modify env
       @app.call(env)
    end
  end
end

I'm not sure how I'd then get the modified env back, do you have to
literally modify something like env['query_string'], also at this
point the content length would be different so I'd have to update that
also.

Most of the applications I've seen are an endpoint and an app in
itself than sitting in the middle of the incoming request, and I'm yet
to find an example of modifying the incoming params.

Any help on this would be greatly appreciated

All the best.

RobL

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using Rack Middlware to filter parameters
  2009-11-05 11:02 Using Rack Middlware to filter parameters RobL
@ 2009-11-05 22:32 ` Iñaki Baz Castillo
  2009-11-05 23:24   ` Martin
  0 siblings, 1 reply; 3+ messages in thread
From: Iñaki Baz Castillo @ 2009-11-05 22:32 UTC (permalink / raw)
  To: rack-devel


El Jueves, 5 de Noviembre de 2009, RobL escribió:
> Hi there,
> 
> I wanted to ask if anyone could point me in the direction of some code
> examples where you can use Rack Middleware to filter incoming
> parameters.

> But as a very tivial example I want be able to do something like
> 
> module Rack
>   class Myfilter
>     def initialize(app)
>       @app = app
>     end
> 
>     def call(env)
>        request = Rack::Request.new(env)
>        request.params.delete('someparam')
>        # but at this point I want/need to modify env
>        @app.call(env)
>     end
>   end
> end
> 
> I'm not sure how I'd then get the modified env back, do you have to
> literally modify something like env['query_string'], also at this
> point the content length would be different so I'd have to update that
> also.

Do you mean parameters in the request URI? or in the body? in the first case 
the content-length should not be modified.

 
> Most of the applications I've seen are an endpoint and an app in
> itself than sitting in the middle of the incoming request, and I'm yet
> to find an example of modifying the incoming params.

I expect that Rack is not designed for that, as changing the request is not a 
very common usage (IMHO).

-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using Rack Middlware to filter parameters
  2009-11-05 22:32 ` Iñaki Baz Castillo
@ 2009-11-05 23:24   ` Martin
  0 siblings, 0 replies; 3+ messages in thread
From: Martin @ 2009-11-05 23:24 UTC (permalink / raw)
  To: rack-devel


An example of rack middleware that modifies the request:
http://github.com/mynyml/rack-abstract-format/blob/master/lib/rack/abstract_format.rb

On Thu, Nov 5, 2009 at 5:32 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
>
> El Jueves, 5 de Noviembre de 2009, RobL escribió:
>> Hi there,
>>
>> I wanted to ask if anyone could point me in the direction of some code
>> examples where you can use Rack Middleware to filter incoming
>> parameters.
>
>> But as a very tivial example I want be able to do something like
>>
>> module Rack
>>   class Myfilter
>>     def initialize(app)
>>       @app = app
>>     end
>>
>>     def call(env)
>>        request = Rack::Request.new(env)
>>        request.params.delete('someparam')
>>        # but at this point I want/need to modify env
>>        @app.call(env)
>>     end
>>   end
>> end
>>
>> I'm not sure how I'd then get the modified env back, do you have to
>> literally modify something like env['query_string'], also at this
>> point the content length would be different so I'd have to update that
>> also.
>
> Do you mean parameters in the request URI? or in the body? in the first case
> the content-length should not be modified.
>
>
>> Most of the applications I've seen are an endpoint and an app in
>> itself than sitting in the middle of the incoming request, and I'm yet
>> to find an example of modifying the incoming params.
>
> I expect that Rack is not designed for that, as changing the request is not a
> very common usage (IMHO).
>
> --
> Iñaki Baz Castillo <ibc@aliax.net>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-05 23:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-05 11:02 Using Rack Middlware to filter parameters RobL
2009-11-05 22:32 ` Iñaki Baz Castillo
2009-11-05 23:24   ` Martin

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/rack.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).