Actually there's no middleware anymore

This commit is contained in:
Sdogruyol 2016-12-04 01:43:30 +03:00
parent 1afb4cbfa8
commit eb64b52f84
7 changed files with 17 additions and 19 deletions

View file

@ -2,7 +2,6 @@ require "http"
require "multipart"
require "./kemal/*"
require "./kemal/helpers/*"
require "./kemal/middleware/*"
module Kemal
# The command to run a `Kemal` application.

View file

@ -49,7 +49,7 @@ module Kemal
puts "SSL Certificate Not Found"
exit
end
ssl = Kemal::Middleware::SSL.new
ssl = Kemal::SSL.new
ssl.set_key_file @key_file.not_nil!
ssl.set_cert_file @cert_file.not_nil!
Kemal.config.ssl = ssl.context

View file

@ -1,12 +1,12 @@
module Kemal::Middleware
# Kemal::Filter handle all code that should be evaluated before and after
module Kemal
# Kemal::FilterHandler handle all code that should be evaluated before and after
# every request
class Filter < HTTP::Handler
class FilterHandler < HTTP::Handler
INSTANCE = new
# This middleware is lazily instantiated and added to the handlers as soon as a call to `after_X` or `before_X` is made.
def initialize
@tree = Radix::Tree(Array(Kemal::Middleware::FilterBlock)).new
@tree = Radix::Tree(Array(Kemal::FilterBlock)).new
Kemal.config.add_filter_handler(self)
end
@ -91,7 +91,7 @@ ALL_METHODS = %w(get post put patch delete all)
{% for type in ["before", "after"] %}
{% for method in ALL_METHODS %}
def {{type.id}}_{{method.id}}(path = "*", &block : HTTP::Server::Context -> _)
Kemal::Middleware::Filter::INSTANCE.{{type.id}}({{method}}.upcase, path, &block)
Kemal::FilterHandler::INSTANCE.{{type.id}}({{method}}.upcase, path, &block)
end
{% end %}
{% end %}

View file

@ -1,5 +1,4 @@
module Kemal::Middleware
# This middleware adds SSL / TLS support.
module Kemal
class SSL
getter context