mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add log macro
This commit is contained in:
parent
265bfb1db2
commit
aabfe4ff99
3 changed files with 14 additions and 4 deletions
|
@ -18,6 +18,7 @@ describe "Logger" do
|
||||||
logger = Kemal::Logger.new
|
logger = Kemal::Logger.new
|
||||||
logger.handler.should be_a File
|
logger.handler.should be_a File
|
||||||
end
|
end
|
||||||
|
|
||||||
it "writes to a file in production" do
|
it "writes to a file in production" do
|
||||||
config = Kemal.config
|
config = Kemal.config
|
||||||
config.env = "production"
|
config.env = "production"
|
||||||
|
|
|
@ -34,3 +34,10 @@ end
|
||||||
macro public_folder(path)
|
macro public_folder(path)
|
||||||
Kemal.config.public_folder = {{path}}
|
Kemal.config.public_folder = {{path}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Logs to output stream.
|
||||||
|
# development: STDOUT in
|
||||||
|
# production: kemal.log
|
||||||
|
macro log(message)
|
||||||
|
Kemal::Logger::INSTANCE.write "#{{{message}}}\n"
|
||||||
|
end
|
||||||
|
|
|
@ -8,8 +8,10 @@ module Kemal::Middleware
|
||||||
# Kemal.config.add_handler auth_handler
|
# Kemal.config.add_handler auth_handler
|
||||||
#
|
#
|
||||||
class HTTPBasicAuth < HTTP::Handler
|
class HTTPBasicAuth < HTTP::Handler
|
||||||
BASIC = "Basic"
|
BASIC = "Basic"
|
||||||
AUTH = "Authorization"
|
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)
|
def initialize(@username, @password)
|
||||||
end
|
end
|
||||||
|
@ -23,8 +25,8 @@ module Kemal::Middleware
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
headers = HTTP::Headers.new
|
headers = HTTP::Headers.new
|
||||||
headers["WWW-Authenticate"] = "Basic realm=\"Login Required\""
|
headers["WWW-Authenticate"] = HEADER_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)
|
HTTP::Response.new(401, AUTH_MESSAGE, headers, nil, "HTTP/1.1", nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized?(value)
|
def authorized?(value)
|
||||||
|
|
Loading…
Reference in a new issue