Thanks guys, this is very promising.  I think I've almost got a
middleware app going.  I've got the following class:

class CustomHandler

  def initialize(app)
    puts "Initialized..."
    @app = app
  end

  def call(env)
    if env["PATH_INFO"] =~ /\/bad_path\//
      [201, {"Content-Type" => "text/html"}, "Ingored"]
    end
    @app.call(env)
  end

end

And I add the middleware like so in environment.rb:

  config.middleware.insert_before(ActionController::ParamsParser,
CustomHandler )

However, at runtime I get this complaint:

  Status: 500 Internal Server Error
  undefined method `call' for CustomHandler:Class

So, obviously it is trying to invoke 'call' on the class, rather than
an instance of the class.  What's confusing me is that I had to add
that constructor that takes the app to the class, or it failed during
the insert_before(), so I assumed that rack was reflectively creating
an instance.

The code above, structurally, is identical to the ParamsParser code: a
single-arg constructor and a non-static call method, so I must be
doing something wrong in the insert_before code.  Do I need to pass an
instance, rather than the class in?  If so, how can I get at the app?

Thanks for all your help everyone,
Carson

On Mar 17, 5:09 pm, Dan Croak <[email protected]> wrote:
> Peeking into the Rails 2.3.8, params parsing is handled by
> ActionContoller::ParamsParser, which is located in
> actionpack/lib/action_controller/params_parser.rb:
>
> https://github.com/rails/rails/blob/240f4e944cd90fca138aba84674560439...
>
> ParamsParser is a Rack app which is autoloaded inside the
> ActionController module:
>
> https://github.com/rails/rails/blob/240f4e944cd90fca138aba84674560439...
>
> So, I think you want a Rack app as Jeff suggested:
>
>  class CustomXmlHandler
>     def self.call(env)
>       if env["PATH_INFO"] =~ /^\/big-xml-requests/
>         DatabaseObject.create :xml => request.raw_post
>         [201, {"Content-Type" => "text/html"}, "XML saved"]
>       else
>         [404, {"Content-Type" => "text/html"}, "Not Found"]
>       end
>     end
>   end
>
> Then, insert it as middleware before the built-in Rails params parser
> in config/environment.rb:
>
> configuration.middleware.insert_before ActionContoller::ParamsParser,
> CustomXmlHandler
>
> On Sat, Mar 17, 2012 at 7:26 PM, Jeff Schmitz
>
>
>
>
>
>
>
> <[email protected]> wrote:
> > Can you do this part as a rack app?
>
> > Jeff
>
> > On Mar 17, 2012, at 4:32 PM, Carson  Gross <[email protected]> wrote:
>
> >> According to my tests, yes, the parameter parsing happens before the
> >> before_filters are run.
>
> >> Thanks,
> >> Carson
>
> >> On Mar 17, 11:15 am, Jeff Schmitz <[email protected]> wrote:
> >>> Does Rails parse the body prior to any before_filters run?
>
> >>> Jeff
>
> >>> On Mar 17, 2012, at 12:57 PM, Carson  Gross <[email protected]> wrote:
>
> >>>> Hey Guys,
>
> >>>> This is a rails question, so please ignore if that doesn't interest
> >>>> you.
>
> >>>> Does anyone know if there is a way to make rails *not* parse the body
> >>>> of an XML post to a given controller method?  I've been googling for
> >>>> an hour now and can't figure it out.  Basically we've got some huge
> >>>> XML docs coming in and we'd like to just jam them into the database as
> >>>> text and then process them in the background using nokogiri.
>
> >>>> Unfortunately, rails is still parsing them using REXML before they
> >>>> ever hit our controller which I just realized after a week of pulling
> >>>> my hair out: the perf issue doesn't show up in New Relic because all
> >>>> the processing time is *before* the request.
>
> >>>> We could switch the body to something like CSV, but I'm hoping there
> >>>> is a way to tell rails to just not bother parsing the body, so we can
> >>>> just grab it with:
>
> >>>>  request.body.read
>
> >>>> This is rails 2.3.8.
>
> >>>> Thanks,
> >>>> Carson
>
> >>>> --
> >>>> You received this message because you are subscribed to the Google 
> >>>> Groups "Heroku" group.
> >>>> To post to this group, send email to [email protected].
> >>>> To unsubscribe from this group, send email to 
> >>>> [email protected].
> >>>> For more options, visit this group 
> >>>> athttp://groups.google.com/group/heroku?hl=en.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups 
> >> "Heroku" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to 
> >> [email protected].
> >> For more options, visit this group 
> >> athttp://groups.google.com/group/heroku?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Heroku" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/heroku?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.

Reply via email to