lib/goliath/rack/validation/request_method.rb in goliath-0.9.1 vs lib/goliath/rack/validation/request_method.rb in goliath-0.9.2
- old
+ new
@@ -1,16 +1,17 @@
-require 'goliath/rack/validation_error'
+require 'goliath/rack/validator'
module Goliath
module Rack
module Validation
# A middleware to validate that the request had a given HTTP method.
#
# @example
# use Goliath::Rack::Validation::RequestMethod, %w(GET POST)
#
class RequestMethod
+ include Goliath::Rack::Validator
attr_reader :methods
ERROR = 'Invalid request method'
# Called by the framework to create the Goliath::Rack::Validation::RequestMethod validator
@@ -22,10 +23,10 @@
@app = app
@methods = methods
end
def call(env)
- raise Goliath::Validation::Error.new(400, ERROR) unless methods.include?(env['REQUEST_METHOD'])
+ return validation_error(405, ERROR, "Allow" => methods.map{|m| m.to_s.upcase}.join(', ')) unless methods.include?(env['REQUEST_METHOD'])
@app.call(env)
end
end
end
end
\ No newline at end of file