diff --git a/spec/logger_spec.cr b/spec/logger_spec.cr index e450c97..824498c 100644 --- a/spec/logger_spec.cr +++ b/spec/logger_spec.cr @@ -18,6 +18,7 @@ describe "Logger" do logger = Kemal::Logger.new logger.handler.should be_a File end + it "writes to a file in production" do config = Kemal.config config.env = "production" diff --git a/src/kemal/macros.cr b/src/kemal/macros.cr index 972d2aa..3bea929 100644 --- a/src/kemal/macros.cr +++ b/src/kemal/macros.cr @@ -34,3 +34,10 @@ end macro public_folder(path) Kemal.config.public_folder = {{path}} end + +# Logs to output stream. +# development: STDOUT in +# production: kemal.log +macro log(message) + Kemal::Logger::INSTANCE.write "#{{{message}}}\n" +end diff --git a/src/kemal/middleware/http_basic_auth.cr b/src/kemal/middleware/http_basic_auth.cr index bdbf72e..77756a3 100644 --- a/src/kemal/middleware/http_basic_auth.cr +++ b/src/kemal/middleware/http_basic_auth.cr @@ -8,8 +8,10 @@ module Kemal::Middleware # Kemal.config.add_handler auth_handler # class HTTPBasicAuth < HTTP::Handler - BASIC = "Basic" - AUTH = "Authorization" + BASIC = "Basic" + AUTH = "Authorization" + AUTH_MESSAGE = "Could not verify your access level for that URL.\nYou have to login with proper credentials" + HEADER_LOGIN_REQUIRED = "Basic realm=\"Login Required\"" def initialize(@username, @password) end @@ -23,8 +25,8 @@ module Kemal::Middleware end end headers = HTTP::Headers.new - headers["WWW-Authenticate"] = "Basic realm=\"Login Required\"" - HTTP::Response.new(401, "Could not verify your access level for that URL.\nYou have to login with proper credentials", headers, nil, "HTTP/1.1", nil) + headers["WWW-Authenticate"] = HEADER_LOGIN_REQUIRED + HTTP::Response.new(401, AUTH_MESSAGE, headers, nil, "HTTP/1.1", nil) end def authorized?(value)