Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
eb1832acaf
8 changed files with 67 additions and 14 deletions
|
@ -1,4 +1,11 @@
|
||||||
# 1.0.0 (??-03-2021)
|
# 1.1.0 (02-09-2021)
|
||||||
|
|
||||||
|
- You can now set your own application name for startup message [#606](https://github.com/kemalcr/kemal/pull/606). Thanks @aravindavk :pray:
|
||||||
|
- Add array of paths support for before/after filters [#605](https://github.com/kemalcr/kemal/pull/605). Thanks @sdogruyol :pray:
|
||||||
|
- Fixed executing filters when before and after is defined at the same time [#612](https://github.com/kemalcr/kemal/pull/612). Thanks @mamantoha :pray:
|
||||||
|
- Set content type to text/html for 500 exceptions [#616](https://github.com/kemalcr/kemal/pull/616). Thanks @sdogruyol :pray:
|
||||||
|
|
||||||
|
# 1.0.0 (22-03-2021)
|
||||||
|
|
||||||
- Crystal 1.0.0 support :tada:
|
- Crystal 1.0.0 support :tada:
|
||||||
- Update Radix to use latest 0.4.0 [#596](https://github.com/kemalcr/kemal/pull/596). Thanks @luislavena :pray:
|
- Update Radix to use latest 0.4.0 [#596](https://github.com/kemalcr/kemal/pull/596). Thanks @luislavena :pray:
|
||||||
|
|
|
@ -58,7 +58,7 @@ See also [Getting Started](http://kemalcr.com/guide/).
|
||||||
- Middleware support
|
- Middleware support
|
||||||
- Built-in JSON support
|
- Built-in JSON support
|
||||||
- Built-in static file serving
|
- Built-in static file serving
|
||||||
- Built-in view templating via [Kilt](https://github.com/jeromegn/kilt)
|
- Built-in view templating via [ECR](https://crystal-lang.org/api/ECR.html)
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: kemal
|
name: kemal
|
||||||
version: 1.0.0
|
version: 1.1.0
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Serdar Dogruyol <dogruyolserdar@gmail.com>
|
- Serdar Dogruyol <dogruyolserdar@gmail.com>
|
||||||
|
@ -8,9 +8,6 @@ dependencies:
|
||||||
radix:
|
radix:
|
||||||
github: luislavena/radix
|
github: luislavena/radix
|
||||||
version: ~> 0.4.0
|
version: ~> 0.4.0
|
||||||
kilt:
|
|
||||||
github: jeromegn/kilt
|
|
||||||
version: ~> 0.6.0
|
|
||||||
exception_page:
|
exception_page:
|
||||||
github: crystal-loot/exception_page
|
github: crystal-loot/exception_page
|
||||||
version: ~> 0.2.0
|
version: ~> 0.2.0
|
||||||
|
|
|
@ -59,6 +59,30 @@ describe "Kemal::ExceptionHandler" do
|
||||||
response.body.should eq "Something happened"
|
response.body.should eq "Something happened"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "overrides the content type for filters" do
|
||||||
|
before_get do |env|
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
end
|
||||||
|
error 500 do |_, err|
|
||||||
|
err.message
|
||||||
|
end
|
||||||
|
get "/" do |env|
|
||||||
|
env.response.status_code = 500
|
||||||
|
end
|
||||||
|
request = HTTP::Request.new("GET", "/")
|
||||||
|
io = IO::Memory.new
|
||||||
|
response = HTTP::Server::Response.new(io)
|
||||||
|
context = HTTP::Server::Context.new(request, response)
|
||||||
|
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
||||||
|
Kemal::ExceptionHandler::INSTANCE.call(context)
|
||||||
|
response.close
|
||||||
|
io.rewind
|
||||||
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
||||||
|
response.status_code.should eq 500
|
||||||
|
response.headers["Content-Type"].should eq "text/html"
|
||||||
|
response.body.should eq "Rendered error with 500"
|
||||||
|
end
|
||||||
|
|
||||||
it "keeps the specified error Content-Type" do
|
it "keeps the specified error Content-Type" do
|
||||||
error 500 do
|
error 500 do
|
||||||
"Something happened"
|
"Something happened"
|
||||||
|
|
|
@ -183,6 +183,30 @@ describe "Kemal::FilterHandler" do
|
||||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||||
client_response.body.should eq("true")
|
client_response.body.should eq("true")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "executes code before and after request" do
|
||||||
|
before_filter = FilterTest.new
|
||||||
|
before_filter.modified = "false"
|
||||||
|
|
||||||
|
after_filter = FilterTest.new
|
||||||
|
after_filter.modified = "false"
|
||||||
|
|
||||||
|
filter_middleware = Kemal::FilterHandler.new
|
||||||
|
filter_middleware._add_route_filter("ALL", "*", :before) { before_filter.modified = "true" }
|
||||||
|
filter_middleware._add_route_filter("ALL", "*", :after) { after_filter.modified = "true" }
|
||||||
|
|
||||||
|
kemal = Kemal::RouteHandler::INSTANCE
|
||||||
|
kemal.add_route "GET", "/" { "#{before_filter.modified}-#{after_filter.modified}" }
|
||||||
|
|
||||||
|
before_filter.modified.should eq("false")
|
||||||
|
after_filter.modified.should eq("false")
|
||||||
|
|
||||||
|
request = HTTP::Request.new("GET", "/")
|
||||||
|
create_request_and_return_io_and_context(filter_middleware, request)
|
||||||
|
io_with_context = create_request_and_return_io_and_context(kemal, request)[0]
|
||||||
|
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||||
|
client_response.body.should eq("true-true")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class FilterTest
|
class FilterTest
|
||||||
|
|
|
@ -71,7 +71,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
|
|
||||||
private def radix_path(verb : String?, path : String, type : Symbol)
|
private def radix_path(verb : String?, path : String, type : Symbol)
|
||||||
"#{type}/#{verb}/#{path}"
|
"/#{type}/#{verb}/#{path}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
require "kilt"
|
|
||||||
|
|
||||||
CONTENT_FOR_BLOCKS = Hash(String, Tuple(String, Proc(String))).new
|
CONTENT_FOR_BLOCKS = Hash(String, Tuple(String, Proc(String))).new
|
||||||
|
|
||||||
# `content_for` is a set of helpers that allows you to capture
|
# `content_for` is a set of helpers that allows you to capture
|
||||||
|
@ -37,9 +35,9 @@ CONTENT_FOR_BLOCKS = Hash(String, Tuple(String, Proc(String))).new
|
||||||
# setting the appropriate set of tags that should be added to the layout.
|
# setting the appropriate set of tags that should be added to the layout.
|
||||||
macro content_for(key, file = __FILE__)
|
macro content_for(key, file = __FILE__)
|
||||||
%proc = ->() {
|
%proc = ->() {
|
||||||
__kilt_io__ = IO::Memory.new
|
__view_io__ = IO::Memory.new
|
||||||
{{ yield }}
|
{{ yield }}
|
||||||
__kilt_io__.to_s
|
__view_io__.to_s
|
||||||
}
|
}
|
||||||
|
|
||||||
CONTENT_FOR_BLOCKS[{{key}}] = Tuple.new {{file}}, %proc
|
CONTENT_FOR_BLOCKS[{{key}}] = Tuple.new {{file}}, %proc
|
||||||
|
@ -62,13 +60,15 @@ end
|
||||||
# ```
|
# ```
|
||||||
macro render(filename, layout)
|
macro render(filename, layout)
|
||||||
__content_filename__ = {{filename}}
|
__content_filename__ = {{filename}}
|
||||||
content = render {{filename}}
|
io = IO::Memory.new
|
||||||
render {{layout}}
|
content = ECR.embed {{filename}}, io
|
||||||
|
ECR.embed {{layout}}, io
|
||||||
|
io.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
# Render view with the given filename.
|
# Render view with the given filename.
|
||||||
macro render(filename)
|
macro render(filename)
|
||||||
Kilt.render({{filename}})
|
ECR.render({{filename}})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Halt execution with the current context.
|
# Halt execution with the current context.
|
||||||
|
|
|
@ -22,6 +22,7 @@ def render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_500(context, exception, verbosity)
|
def render_500(context, exception, verbosity)
|
||||||
|
context.response.content_type = "text/html"
|
||||||
context.response.status_code = 500
|
context.response.status_code = 500
|
||||||
|
|
||||||
template = if verbosity
|
template = if verbosity
|
||||||
|
|
Loading…
Reference in a new issue