diff --git a/src/kemal.cr b/src/kemal.cr index 47e082a..a57580c 100644 --- a/src/kemal.cr +++ b/src/kemal.cr @@ -1,3 +1,4 @@ +require "http" require "./kemal/*" require "./kemal/helpers/*" require "./kemal/middleware/*" diff --git a/src/kemal/base_log_handler.cr b/src/kemal/base_log_handler.cr index e5c279a..7e6f569 100644 --- a/src/kemal/base_log_handler.cr +++ b/src/kemal/base_log_handler.cr @@ -1,5 +1,3 @@ -require "http" - # All loggers must inherit from `Kemal::BaseLogHandler`. class Kemal::BaseLogHandler < HTTP::Handler def initialize diff --git a/src/kemal/common_log_handler.cr b/src/kemal/common_log_handler.cr index 795cf6b..00e793e 100644 --- a/src/kemal/common_log_handler.cr +++ b/src/kemal/common_log_handler.cr @@ -1,5 +1,3 @@ -require "http" - class Kemal::CommonLogHandler < Kemal::BaseLogHandler @handler : IO::FileDescriptor getter handler diff --git a/src/kemal/middleware/csrf.cr b/src/kemal/middleware/csrf.cr index 9ae841f..c350303 100644 --- a/src/kemal/middleware/csrf.cr +++ b/src/kemal/middleware/csrf.cr @@ -1,5 +1,4 @@ require "secure_random" -require "http" module Kemal::Middleware # This middleware adds CSRF protection to your application. @@ -11,9 +10,9 @@ module Kemal::Middleware # where an attacker can re-submit a form. # class CSRF < HTTP::Handler - HEADER = "X_CSRF_TOKEN" - ALLOWED_METHODS = %w[GET HEAD OPTIONS TRACE] - PARAMETER_NAME = "authenticity_token" + HEADER = "X_CSRF_TOKEN" + ALLOWED_METHODS = %w(GET HEAD OPTIONS TRACE) + PARAMETER_NAME = "authenticity_token" def call(context) unless context.session["csrf"]? @@ -24,12 +23,12 @@ module Kemal::Middleware req = context.request submitted = if req.headers[HEADER]? - req.headers[HEADER] - elsif context.params.body[PARAMETER_NAME]? - context.params.body[PARAMETER_NAME] - else - "nothing" - end + req.headers[HEADER] + elsif context.params.body[PARAMETER_NAME]? + context.params.body[PARAMETER_NAME] + else + "nothing" + end current_token = context.session["csrf"] if current_token == submitted @@ -41,6 +40,5 @@ module Kemal::Middleware context.response.print "Forbidden" end end - end end