Compare commits
9 commits
bba5bef505
...
eb1832acaf
Author | SHA1 | Date | |
---|---|---|---|
eb1832acaf | |||
|
5e2efec050 | ||
|
db0a6b8dc6 | ||
|
0ab0ecb7c6 | ||
|
a251ede5bd | ||
|
5473312f3d | ||
|
523340b036 | ||
|
64733c10e0 | ||
|
14aabb8907 |
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:
|
||||
- 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
|
||||
- Built-in JSON support
|
||||
- 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
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: kemal
|
||||
version: 1.0.0
|
||||
version: 1.1.0
|
||||
|
||||
authors:
|
||||
- Serdar Dogruyol <dogruyolserdar@gmail.com>
|
||||
|
@ -8,9 +8,6 @@ dependencies:
|
|||
radix:
|
||||
github: luislavena/radix
|
||||
version: ~> 0.4.0
|
||||
kilt:
|
||||
github: jeromegn/kilt
|
||||
version: ~> 0.6.0
|
||||
exception_page:
|
||||
github: crystal-loot/exception_page
|
||||
version: ~> 0.2.0
|
||||
|
|
|
@ -59,6 +59,30 @@ describe "Kemal::ExceptionHandler" do
|
|||
response.body.should eq "Something happened"
|
||||
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
|
||||
error 500 do
|
||||
"Something happened"
|
||||
|
|
|
@ -183,6 +183,30 @@ describe "Kemal::FilterHandler" do
|
|||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
client_response.body.should eq("true")
|
||||
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
|
||||
|
||||
class FilterTest
|
||||
|
|
|
@ -71,7 +71,7 @@ module Kemal
|
|||
end
|
||||
|
||||
private def radix_path(verb : String?, path : String, type : Symbol)
|
||||
"#{type}/#{verb}/#{path}"
|
||||
"/#{type}/#{verb}/#{path}"
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "kilt"
|
||||
|
||||
CONTENT_FOR_BLOCKS = Hash(String, Tuple(String, Proc(String))).new
|
||||
|
||||
# `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.
|
||||
macro content_for(key, file = __FILE__)
|
||||
%proc = ->() {
|
||||
__kilt_io__ = IO::Memory.new
|
||||
__view_io__ = IO::Memory.new
|
||||
{{ yield }}
|
||||
__kilt_io__.to_s
|
||||
__view_io__.to_s
|
||||
}
|
||||
|
||||
CONTENT_FOR_BLOCKS[{{key}}] = Tuple.new {{file}}, %proc
|
||||
|
@ -62,13 +60,15 @@ end
|
|||
# ```
|
||||
macro render(filename, layout)
|
||||
__content_filename__ = {{filename}}
|
||||
content = render {{filename}}
|
||||
render {{layout}}
|
||||
io = IO::Memory.new
|
||||
content = ECR.embed {{filename}}, io
|
||||
ECR.embed {{layout}}, io
|
||||
io.to_s
|
||||
end
|
||||
|
||||
# Render view with the given filename.
|
||||
macro render(filename)
|
||||
Kilt.render({{filename}})
|
||||
ECR.render({{filename}})
|
||||
end
|
||||
|
||||
# Halt execution with the current context.
|
||||
|
|
|
@ -22,6 +22,7 @@ def render_404
|
|||
end
|
||||
|
||||
def render_500(context, exception, verbosity)
|
||||
context.response.content_type = "text/html"
|
||||
context.response.status_code = 500
|
||||
|
||||
template = if verbosity
|
||||
|
|
Loading…
Reference in a new issue