make filters pluggable
This commit is contained in:
parent
7b47863014
commit
5166e65e84
|
@ -3,12 +3,11 @@ class Travis::Web::App
|
||||||
autoload :Endpoint, 'travis/web/app/filter/endpoint'
|
autoload :Endpoint, 'travis/web/app/filter/endpoint'
|
||||||
autoload :Assets, 'travis/web/app/filter/assets'
|
autoload :Assets, 'travis/web/app/filter/assets'
|
||||||
|
|
||||||
attr_reader :app, :config, :filters
|
attr_reader :app, :config
|
||||||
|
|
||||||
def initialize(app, config)
|
def initialize(app, config)
|
||||||
@app = app
|
@app = app
|
||||||
@config = config
|
@config = config
|
||||||
@filters = [Endpoint.new(config), Assets.new(config)]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
|
@ -27,6 +26,10 @@ class Travis::Web::App
|
||||||
[headers, filtered]
|
[headers, filtered]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filters
|
||||||
|
@filters ||= Filter.constants.map { |name| Filter.const_get(name).new(config) }
|
||||||
|
end
|
||||||
|
|
||||||
def content_type?(headers, type)
|
def content_type?(headers, type)
|
||||||
headers.any? { |key, value| key.downcase == 'content-type' and value.start_with?(type) }
|
headers.any? { |key, value| key.downcase == 'content-type' and value.start_with?(type) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user