mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Rename common_log_handler and common_exception_handler
This commit is contained in:
parent
ac56973663
commit
5d737ee8f3
6 changed files with 21 additions and 21 deletions
|
@ -1,6 +1,6 @@
|
||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
|
|
||||||
describe "Kemal::CommonExceptionHandler" do
|
describe "Kemal::ExceptionHandler" do
|
||||||
it "renders 404 on route not found" do
|
it "renders 404 on route not found" do
|
||||||
get "/" do |env|
|
get "/" do |env|
|
||||||
"Hello"
|
"Hello"
|
||||||
|
@ -10,7 +10,7 @@ describe "Kemal::CommonExceptionHandler" do
|
||||||
io = IO::Memory.new
|
io = IO::Memory.new
|
||||||
response = HTTP::Server::Response.new(io)
|
response = HTTP::Server::Response.new(io)
|
||||||
context = HTTP::Server::Context.new(request, response)
|
context = HTTP::Server::Context.new(request, response)
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
Kemal::ExceptionHandler::INSTANCE.call(context)
|
||||||
response.close
|
response.close
|
||||||
io.rewind
|
io.rewind
|
||||||
response = HTTP::Client::Response.from_io(io, decompress: false)
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
||||||
|
@ -28,8 +28,8 @@ describe "Kemal::CommonExceptionHandler" do
|
||||||
io = IO::Memory.new
|
io = IO::Memory.new
|
||||||
response = HTTP::Server::Response.new(io)
|
response = HTTP::Server::Response.new(io)
|
||||||
context = HTTP::Server::Context.new(request, response)
|
context = HTTP::Server::Context.new(request, response)
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
Kemal::ExceptionHandler::INSTANCE.call(context)
|
||||||
response.close
|
response.close
|
||||||
io.rewind
|
io.rewind
|
||||||
response = HTTP::Client::Response.from_io(io, decompress: false)
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
||||||
|
@ -49,8 +49,8 @@ describe "Kemal::CommonExceptionHandler" do
|
||||||
io = IO::Memory.new
|
io = IO::Memory.new
|
||||||
response = HTTP::Server::Response.new(io)
|
response = HTTP::Server::Response.new(io)
|
||||||
context = HTTP::Server::Context.new(request, response)
|
context = HTTP::Server::Context.new(request, response)
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
Kemal::ExceptionHandler::INSTANCE.call(context)
|
||||||
response.close
|
response.close
|
||||||
io.rewind
|
io.rewind
|
||||||
response = HTTP::Client::Response.from_io(io, decompress: false)
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
||||||
|
@ -71,8 +71,8 @@ describe "Kemal::CommonExceptionHandler" do
|
||||||
io = IO::Memory.new
|
io = IO::Memory.new
|
||||||
response = HTTP::Server::Response.new(io)
|
response = HTTP::Server::Response.new(io)
|
||||||
context = HTTP::Server::Context.new(request, response)
|
context = HTTP::Server::Context.new(request, response)
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
Kemal::ExceptionHandler::INSTANCE.call(context)
|
||||||
response.close
|
response.close
|
||||||
io.rewind
|
io.rewind
|
||||||
response = HTTP::Client::Response.from_io(io, decompress: false)
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
||||||
|
@ -93,8 +93,8 @@ describe "Kemal::CommonExceptionHandler" do
|
||||||
io = IO::Memory.new
|
io = IO::Memory.new
|
||||||
response = HTTP::Server::Response.new(io)
|
response = HTTP::Server::Response.new(io)
|
||||||
context = HTTP::Server::Context.new(request, response)
|
context = HTTP::Server::Context.new(request, response)
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
||||||
Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
Kemal::ExceptionHandler::INSTANCE.call(context)
|
||||||
response.close
|
response.close
|
||||||
io.rewind
|
io.rewind
|
||||||
response = HTTP::Client::Response.from_io(io, decompress: false)
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
|
|
||||||
describe "Kemal::CommonLogHandler" do
|
describe "Kemal::LogHandler" do
|
||||||
it "logs to the given IO" do
|
it "logs to the given IO" do
|
||||||
config = Kemal.config
|
config = Kemal.config
|
||||||
io = IO::Memory.new
|
io = IO::Memory.new
|
||||||
logger = Kemal::CommonLogHandler.new io
|
logger = Kemal::LogHandler.new io
|
||||||
logger.write "Something"
|
logger.write "Something"
|
||||||
io.to_s.should eq "Something"
|
io.to_s.should eq "Something"
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ describe "Kemal::CommonLogHandler" do
|
||||||
context_io = IO::Memory.new
|
context_io = IO::Memory.new
|
||||||
response = HTTP::Server::Response.new(context_io)
|
response = HTTP::Server::Response.new(context_io)
|
||||||
context = HTTP::Server::Context.new(request, response)
|
context = HTTP::Server::Context.new(request, response)
|
||||||
logger = Kemal::CommonLogHandler.new io
|
logger = Kemal::LogHandler.new io
|
||||||
logger.call(context)
|
logger.call(context)
|
||||||
io.to_s.should_not be nil
|
io.to_s.should_not be nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -117,7 +117,7 @@ module Kemal
|
||||||
|
|
||||||
private def setup_log_handler
|
private def setup_log_handler
|
||||||
@logger ||= if @logging
|
@logger ||= if @logging
|
||||||
Kemal::CommonLogHandler.new
|
Kemal::LogHandler.new
|
||||||
else
|
else
|
||||||
Kemal::NullLogHandler.new
|
Kemal::NullLogHandler.new
|
||||||
end
|
end
|
||||||
|
@ -127,7 +127,7 @@ module Kemal
|
||||||
|
|
||||||
private def setup_error_handler
|
private def setup_error_handler
|
||||||
if @always_rescue
|
if @always_rescue
|
||||||
@error_handler ||= Kemal::CommonExceptionHandler.new
|
@error_handler ||= Kemal::ExceptionHandler.new
|
||||||
HANDLERS.insert(@handler_position, @error_handler.not_nil!)
|
HANDLERS.insert(@handler_position, @error_handler.not_nil!)
|
||||||
@handler_position += 1
|
@handler_position += 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Kemal
|
module Kemal
|
||||||
# Handles all the exceptions, including 404, custom errors and 500.
|
# Handles all the exceptions, including 404, custom errors and 500.
|
||||||
class CommonExceptionHandler
|
class ExceptionHandler
|
||||||
include HTTP::Handler
|
include HTTP::Handler
|
||||||
INSTANCE = new
|
INSTANCE = new
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
# goes between the first 4 and the last `Kemal::RouteHandler`.
|
# goes between the first 4 and the last `Kemal::RouteHandler`.
|
||||||
#
|
#
|
||||||
# - `Kemal::InitHandler`
|
# - `Kemal::InitHandler`
|
||||||
# - `Kemal::CommonLogHandler`
|
# - `Kemal::LogHandler`
|
||||||
# - `Kemal::CommonExceptionHandler`
|
# - `Kemal::ExceptionHandler`
|
||||||
# - `Kemal::StaticFileHandler`
|
# - `Kemal::StaticFileHandler`
|
||||||
# - Here goes custom handlers
|
# - Here goes custom handlers
|
||||||
# - `Kemal::RouteHandler`
|
# - `Kemal::RouteHandler`
|
||||||
|
@ -24,7 +24,7 @@ def public_folder(path : String)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Logs the output via `logger`.
|
# Logs the output via `logger`.
|
||||||
# This is the built-in `Kemal::CommonLogHandler` by default which uses STDOUT.
|
# This is the built-in `Kemal::LogHandler` by default which uses STDOUT.
|
||||||
def log(message : String)
|
def log(message : String)
|
||||||
Kemal.config.logger.write "#{message}\n"
|
Kemal.config.logger.write "#{message}\n"
|
||||||
end
|
end
|
||||||
|
@ -39,7 +39,7 @@ def logging(status : Bool)
|
||||||
Kemal.config.logging = status
|
Kemal.config.logging = status
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is used to replace the built-in `Kemal::CommonLogHandler` with a custom logger.
|
# This is used to replace the built-in `Kemal::LogHandler` with a custom logger.
|
||||||
#
|
#
|
||||||
# A custom logger must inherit from `Kemal::BaseLogHandler` and must implement
|
# A custom logger must inherit from `Kemal::BaseLogHandler` and must implement
|
||||||
# `call(env)`, `write(message)` methods.
|
# `call(env)`, `write(message)` methods.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Kemal
|
module Kemal
|
||||||
# Uses `STDOUT` by default and handles the logging of request/response process time.
|
# Uses `STDOUT` by default and handles the logging of request/response process time.
|
||||||
class CommonLogHandler < Kemal::BaseLogHandler
|
class LogHandler < Kemal::BaseLogHandler
|
||||||
@io : IO
|
@io : IO
|
||||||
|
|
||||||
def initialize(@io : IO = STDOUT)
|
def initialize(@io : IO = STDOUT)
|
Loading…
Reference in a new issue