travis-web/waiter/lib/travis/web/allow.rb
Piotr Sarnacki 8959f382c2 Move server/ to waiter/
Apparently server dir conflicts with some scripts in ember-cli
2015-02-03 10:13:48 +01:00

30 lines
714 B
Ruby

module Travis
module Web
class Allow
attr_accessor :app, :allow, :response
def initialize(app, options = {})
@app = app
@allow = options[:allow] || ['GET', 'HEAD']
@response = options.fetch(:response) do
body = 'request method not allowed'
headers = {
'Content-Type' => 'text/plain',
'Allow' => allow.join(', '),
'Content-Length' => body.bytesize.to_s
}
[405, headers, [body]]
end
end
def call(env)
allow?(env) ? app.call(env) : response
end
def allow?(env)
allow.include? env['REQUEST_METHOD']
end
end
end
end