[英]How to determine the request type in Rack middleware
I have the following Rack middleware to detect old versions of internet explorer:我有以下机架中间件来检测旧版本的 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.我想要做的是向 if 语句添加另一个条件,即允许所有 POST 请求。 Is this possible in the middleware?
这在中间件中可能吗?
There's a method in the Rack::Request object: request.post?
Rack::Request 对象中有一个方法:
request.post?
there are also .get?
还有
.get?
.patch?
.put?
, etc. , 等等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.