AnApprentice
AnApprentice

Reputation: 110960

How to determine the request type in Rack middleware

I have the following Rack middleware to detect old versions of internet explorer:

require 'user_agent'

module Rack
  class IERedirect

    def initialize(app, url)
      @app = app
      @redirect_url = url
    end

    def call(env)
      request = Rack::Request.new(env)
      useragent = UserAgent.new(env["HTTP_USER_AGENT"].to_s)
      path = env["PATH_INFO"]
      if (useragent.name == :ie && (useragent.version.to_i < 10))
        [ 302, {'Location'=> "#{@redirect_url}" }, [] ]
      else
        @app.call(env)
      end
    end
  end
end

What I would like to do is add another condition to the if statement which is to allow all POST requests. Is this possible in the middleware?

Upvotes: 0

Views: 490

Answers (1)

user1476905
user1476905

Reputation: 53

There's a method in the Rack::Request object: request.post? there are also .get? .patch? .put?, etc.

Upvotes: 3

Related Questions