lib/api_proxy/middleware.rb in api_proxy-0.1.1 vs lib/api_proxy/middleware.rb in api_proxy-0.1.2
- old
+ new
@@ -6,16 +6,22 @@
@app = app
@config = ApiProxy.configuration(namespace)
end
def call(env)
- return @app.call(env) unless env['REQUEST_PATH'].start_with?(@config.request_starts_with)
+ return @app.call(env) unless allow_request?(env)
builder = RequestOptionsBuilder.new(env, @config)
request = ApiProxy::Request.new(builder)
response = request.result
Rack::Response.new(response.to_s, response.code, request.headers)
+ end
+
+ def allow_request?(env)
+ return false unless env['REQUEST_PATH'].start_with?(@config.request_starts_with)
+
+ @config.request_allowed.call(env)
end
end
end