This commit is contained in:
Sijawusz Pur Rahnama 2024-04-04 16:20:11 +02:00 committed by GitHub
parent 00266ed8e5
commit 3c74d4c3fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,11 +20,11 @@
- Closes response by default in `HTTP::Server::Context#redirect` [#641](https://github.com/kemalcr/kemal/pull/641). Thanks @cyangle :pray: - Closes response by default in `HTTP::Server::Context#redirect` [#641](https://github.com/kemalcr/kemal/pull/641). Thanks @cyangle :pray:
- Enable option for `index.html` to be a directories default [#640](https://github.com/kemalcr/kemal/pull/640). Thanks @ukd1 :pray: - Enable option for `index.html` to be a directories default [#640](https://github.com/kemalcr/kemal/pull/640). Thanks @ukd1 :pray:
You can enable it via You can enable it via:
```crystal ```crystal
serve_static({"dir_index" => true}) serve_static({"dir_index" => true})
``` ```
# 1.1.2 (24-02-2022) # 1.1.2 (24-02-2022)
@ -75,9 +75,9 @@ serve_static({"dir_index" => true})
- Add option to config to parse or not command line parameters [#483](https://github.com/kemalcr/kemal/pull/483). Thanks @diegogub :pray: - Add option to config to parse or not command line parameters [#483](https://github.com/kemalcr/kemal/pull/483). Thanks @diegogub :pray:
- Allow to set filename for `send_file` [#512](https://github.com/kemalcr/kemal/pull/512). Thanks @mamantoha :pray: - Allow to set filename for `send_file` [#512](https://github.com/kemalcr/kemal/pull/512). Thanks @mamantoha :pray:
```crystal ```crystal
send_file env, "./asset/image.jpeg", filename: "image.jpg" send_file env, "./asset/image.jpeg", filename: "image.jpg"
``` ```
- Set `status_code` before response [#513](https://github.com/kemalcr/kemal/pull/513). Thanks @mamantohoa :pray: - Set `status_code` before response [#513](https://github.com/kemalcr/kemal/pull/513). Thanks @mamantohoa :pray:
- Use Crystal MIME registry. [#516](https://github.com/kemalcr/kemal/pull/516) Thanks @Sija :pray: - Use Crystal MIME registry. [#516](https://github.com/kemalcr/kemal/pull/516) Thanks @Sija :pray:
@ -91,31 +91,31 @@ send_file env, "./asset/image.jpeg", filename: "image.jpg"
- Crystal 0.27.0 support. - Crystal 0.27.0 support.
- *[breaking change]* Added back `env.params.files`. - *[breaking change]* Added back `env.params.files`.
Here's a fully working sample for reading a image file upload `image1` and saving it under `public/uploads`. Here's a fully working sample for reading a image file upload `image1` and saving it under `public/uploads`.
```crystal ```crystal
post "/upload" do |env| post "/upload" do |env|
file = env.params.files["image1"].tempfile file = env.params.files["image1"].tempfile
file_path = ::File.join [Kemal.config.public_folder, "uploads/", File.basename(file.path)] file_path = ::File.join [Kemal.config.public_folder, "uploads/", File.basename(file.path)]
File.open(file_path, "w") do |f| File.open(file_path, "w") do |f|
IO.copy(file, f) IO.copy(file, f)
end end
"Upload ok" "Upload ok"
end end
``` ```
To test To test
`curl -F "image1=@/Users/serdar/Downloads/kemal.png" http://localhost:3000/upload` `curl -F "image1=@/Users/serdar/Downloads/kemal.png" http://localhost:3000/upload`
- Cache HTTP routes to increase performance :rocket: [#493](https://github.com/kemalcr/kemal/pull/493) - Cache HTTP routes to increase performance :rocket: [#493](https://github.com/kemalcr/kemal/pull/493)
# 0.24.0 (14-08-2018) # 0.24.0 (14-08-2018)
- *[breaking change]* Removed `env.params.files`. You can use Crystal's built-in `HTTP::FormData.parse` instead - *[breaking change]* Removed `env.params.files`. You can use Crystal's built-in `HTTP::FormData.parse` instead:
```crystal ```crystal
post "/upload" do |env| post "/upload" do |env|
HTTP::FormData.parse(env.request) do |upload| HTTP::FormData.parse(env.request) do |upload|
filename = file.filename filename = file.filename
@ -128,28 +128,28 @@ post "/upload" do |env|
end end
"Upload OK" "Upload OK"
end end
end end
``` ```
- *[breaking change]* From now on to access dynamic url params in a WebSocket route you have to use: - *[breaking change]* From now on to access dynamic url params in a WebSocket route you have to use:
```crystal ```crystal
ws "/:id" do |socket, context| ws "/:id" do |socket, context|
id = context.ws_route_lookup.params["id"] id = context.ws_route_lookup.params["id"]
end end
``` ```
- *[breaking change]* Removed `_method` magic param. - *[breaking change]* Removed `_method` magic param.
- Added new exception page [#466](https://github.com/kemalcr/kemal/pull/466). Thanks @mamantoha 🙏 - Added new exception page [#466](https://github.com/kemalcr/kemal/pull/466). Thanks @mamantoha 🙏
- Support custom port binding. Thanks @straight-shoota 🙏 - Support custom port binding. Thanks @straight-shoota 🙏
```crystal ```crystal
Kemal.run do |config| Kemal.run do |config|
server = config.server.not_nil! server = config.server.not_nil!
server.bind_tcp "127.0.0.1", 3000, reuse_port: true server.bind_tcp "127.0.0.1", 3000, reuse_port: true
server.bind_tcp "0.0.0.0", 3001, reuse_port: true server.bind_tcp "0.0.0.0", 3001, reuse_port: true
end end
``` ```
# 0.23.0 (17-06-2018) # 0.23.0 (17-06-2018)
@ -172,22 +172,22 @@ end
- Dynamically insert handlers :muscle: Fixes [#376](https://github.com/kemalcr/kemal/pull/376). - Dynamically insert handlers :muscle: Fixes [#376](https://github.com/kemalcr/kemal/pull/376).
- Add context to WebSocket. This allows one to use `HTTP::Server::Context` in `ws` declarations :heart_eyes: Fixes [#349](https://github.com/kemalcr/kemal/pull/349). - Add context to WebSocket. This allows one to use `HTTP::Server::Context` in `ws` declarations :heart_eyes: Fixes [#349](https://github.com/kemalcr/kemal/pull/349).
```crystal ```crystal
ws "/:room_name" do |socket, env| ws "/:room_name" do |socket, env|
env.params.url["room_name"] env.params.url["room_name"]
end end
``` ```
- Add support for customizing the headers of built-in `Kemal::StaticFileHandler` :hammer: Useful for supporting `CORS` for single page applications :clap: - Add support for customizing the headers of built-in `Kemal::StaticFileHandler` :hammer: Useful for supporting `CORS` for single page applications :clap:
```crystal ```crystal
static_headers do |response, filepath, filestat| static_headers do |response, filepath, filestat|
if filepath =~ /\.html$/ if filepath =~ /\.html$/
response.headers.add("Access-Control-Allow-Origin", "*") response.headers.add("Access-Control-Allow-Origin", "*")
end end
response.headers.add("Content-Size", filestat.size.to_s) response.headers.add("Content-Size", filestat.size.to_s)
end end
``` ```
- Allow `%w` in Handler macros [#385](https://github.com/kemalcr/kemal/pull/385). Thanks @will :pray: - Allow `%w` in Handler macros [#385](https://github.com/kemalcr/kemal/pull/385). Thanks @will :pray:
- Security: `X-Content-Type-Options: nosniff` for static files. Fixes [#379](https://github.com/kemalcr/kemal/issues/379). Thanks @crisward :pray: - Security: `X-Content-Type-Options: nosniff` for static files. Fixes [#379](https://github.com/kemalcr/kemal/issues/379). Thanks @crisward :pray:
@ -198,18 +198,18 @@ end
- Crystal 0.23.0 support! As always, Kemal is compatible with the latest major release of Crystal 💎 - Crystal 0.23.0 support! As always, Kemal is compatible with the latest major release of Crystal 💎
- Great news everyone 🎉 All handlers are now completely ***customizable***!. Use the default `Kemal` handlers or go wild, it's all up to you ⛏ - Great news everyone 🎉 All handlers are now completely ***customizable***!. Use the default `Kemal` handlers or go wild, it's all up to you ⛏
```crystal ```crystal
# Don't forget to add `Kemal::RouteHandler::INSTANCE` or your routes won't work! # Don't forget to add `Kemal::RouteHandler::INSTANCE` or your routes won't work!
Kemal.config.handlers = [Kemal::InitHandler.new, YourHandler.new, Kemal::RouteHandler::INSTANCE] Kemal.config.handlers = [Kemal::InitHandler.new, YourHandler.new, Kemal::RouteHandler::INSTANCE]
``` ```
You can also insert a handler into a specific position. You can also insert a handler into a specific position.
```crystal ```crystal
# This adds MyCustomHandler instance to 1 position. # This adds MyCustomHandler instance to 1 position.
# Be aware that the index starts from 0. # Be aware that the index starts from 0.
add_handler MyCustomHandler.new, 1 add_handler MyCustomHandler.new, 1
``` ```
- Updated [Kilt](https://github.com/jeromegn/kilt) to v0.4.0. - Updated [Kilt](https://github.com/jeromegn/kilt) to v0.4.0.
- Make `Route` a `Struct`. This improves the performance of route declarations. - Make `Route` a `Struct`. This improves the performance of route declarations.
@ -220,15 +220,15 @@ add_handler MyCustomHandler.new, 1
- Update Radix to `v0.3.8`. (thanks @waghanza) - Update Radix to `v0.3.8`. (thanks @waghanza)
- User defined context store types. (thanks @neovitange) - User defined context store types. (thanks @neovitange)
```crystal ```crystal
class User class User
property name property name
end end
add_context_storage_type(User) add_context_storage_type(User)
``` ```
- Prevent `send_file returning filesize. (thanks @crisward) - Prevent `send_file` returning filesize. (thanks @crisward)
- Don't call setup in `config#add_filter_handler` fixes [#338](https://github.com/kemalcr/kemal/issues/338). - Don't call setup in `config#add_filter_handler` fixes [#338](https://github.com/kemalcr/kemal/issues/338).
# 0.18.3 (07-03-2017) # 0.18.3 (07-03-2017)
@ -255,31 +255,29 @@ add_context_storage_type(User)
# 0.18.0 (11-02-2017) # 0.18.0 (11-02-2017)
- Simpler file upload. File uploads can now be access from `HTTP::Server::Context` like `env.params.files["filename"]`. - Simpler file upload. File uploads can now be access from `HTTP::Server::Context` like `env.params.files["filename"]`, which exposes following properties.
`env.params.files["filename"]` has 5 methods:
+ `tmpfile`: This is temporary file for file upload. Useful for saving the upload file. + `tmpfile`: This is temporary file for file upload. Useful for saving the upload file.
+ `tmpfile_path`: File path of `tmpfile`. + `tmpfile_path`: File path of `tmpfile`.
+ `filename`: File name of the file upload. (logo.png, images.zip e.g) + `filename`: File name of the file upload. (logo.png, images.zip e.g)
+ `meta`: Meta information for the file upload. + `meta`: Meta information for the file upload.
+ `headers`: Headers for the file upload. + `headers`: Headers for the file upload.
Here's a fully working sample for reading a image file upload `image1` and saving it under `public/uploads`. Here's a fully working sample for reading a image file upload `image1` and saving it under `public/uploads`.
```crystal ```crystal
post "/upload" do |env| post "/upload" do |env|
file = env.params.files["image1"].tmpfile file = env.params.files["image1"].tmpfile
file_path = ::File.join [Kemal.config.public_folder, "uploads/", file.filename] file_path = ::File.join [Kemal.config.public_folder, "uploads/", file.filename]
File.open(file_path, "w") do |f| File.open(file_path, "w") do |f|
IO.copy(file, f) IO.copy(file, f)
end end
"Upload ok" "Upload ok"
end end
``` ```
To test To test
`curl -F "image1=@/Users/serdar/Downloads/kemal.png" http://localhost:3000/upload` `curl -F "image1=@/Users/serdar/Downloads/kemal.png" http://localhost:3000/upload`
- RF7233 support a.k.a file streaming. [#299](https://github.com/kemalcr/kemal/pull/299) (thanks @denysvitali) - RF7233 support a.k.a file streaming. [#299](https://github.com/kemalcr/kemal/pull/299) (thanks @denysvitali)
- Update Radix to 0.3.7. Fixes [#293](https://github.com/kemalcr/kemal/issues/293) - Update Radix to 0.3.7. Fixes [#293](https://github.com/kemalcr/kemal/issues/293)
@ -313,54 +311,50 @@ To test
- Reimplemented Request middleware / filter routing. - Reimplemented Request middleware / filter routing.
Now all requests will first go through the Middleware stack then Filters (`before_*`) and will finally reach the matching route. Now all requests will first go through the Middleware stack then Filters (`before_*`) and will finally reach the matching route.
Which is illustrated as, Which is illustrated as: `Request -> Middleware -> Filter -> Route`
```
Request -> Middleware -> Filter -> Route
```
- Rename `return_with` as `halt`. - Rename `return_with` as `halt`.
- Route declaration must start with `/`. Fixes [#242](https://github.com/kemalcr/kemal/issues/242) - Route declaration must start with `/`. Fixes [#242](https://github.com/kemalcr/kemal/issues/242)
- Set default exception `Content-Type` to `text/html`. Fixes [#202](https://github.com/kemalcr/kemal/issues/242) - Set default exception `Content-Type` to `text/html`. Fixes [#202](https://github.com/kemalcr/kemal/issues/242)
- Add `only` and `exclude` paths for `Kemal::Handler`. This change requires that all handlers must inherit from `Kemal::Handler`. - Add `only` and `exclude` paths for `Kemal::Handler`. This change requires that all handlers must inherit from `Kemal::Handler`.
For example this handler will only work on `/` path. By default the HTTP method is `GET`. For example this handler will only work on `/` path. By default the HTTP method is `GET`.
```crystal ```crystal
class OnlyHandler < Kemal::Handler class OnlyHandler < Kemal::Handler
only ["/"] only ["/"]
def call(env) def call(env)
return call_next(env) unless only_match?(env) return call_next(env) unless only_match?(env)
puts "If the path is / i will be doing some processing here." puts "If the path is / i will be doing some processing here."
end end
end end
``` ```
The handlers using `exclude` will work on the paths that isn't specified. For example this handler will work on any routes other than `/`. The handlers using `exclude` will work on the paths that isn't specified. For example this handler will work on any routes other than `/`.
```crystal ```crystal
class ExcludeHandler < Kemal::Handler class ExcludeHandler < Kemal::Handler
exclude ["/"] exclude ["/"]
def call(env) def call(env)
return call_next(env) unless only_match?(env) return call_next(env) unless only_match?(env)
puts "If the path is NOT / i will be doing some processing here." puts "If the path is NOT / i will be doing some processing here."
end end
end end
``` ```
- Close response on `halt`. (thanks @samueleaton). - Close response on `halt`. (thanks @samueleaton).
- Update Radix to `v0.3.4`. - Update Radix to `v0.3.4`.
- `error` handler now also yields error. For example you can get the error mesasage like - `error` handler now also yields error. For example you can get the error mesasage like:
```crystal ```crystal
error 500 do |env, err| error 500 do |env, err|
err.message err.message
end end
``` ```
- Update `multipart.cr` to `v0.1.1` - Update `multipart.cr` to `v0.1.1`
@ -368,8 +362,8 @@ end
- Improved Multipart support with more info on parsed files. `parse_multipart(env)` now yields an `UploadFile` object which has the following properties: `field`, `data`, `meta` and `headers`. - Improved Multipart support with more info on parsed files. `parse_multipart(env)` now yields an `UploadFile` object which has the following properties: `field`, `data`, `meta` and `headers`.
```crystal ```crystal
post "/upload" do |env| post "/upload" do |env|
parse_multipart(env) do |f| parse_multipart(env) do |f|
image1 = f.data if f.field == "image1" image1 = f.data if f.field == "image1"
image2 = f.data if f.field == "image2" image2 = f.data if f.field == "image2"
@ -377,29 +371,29 @@ post "/upload" do |env|
puts f.headers puts f.headers
"Upload complete" "Upload complete"
end end
end end
``` ```
# 0.16.0 # 0.16.0
- Multipart support <3 (thanks @RX14). Now you can handle file uploads. - Multipart support <3 (thanks @RX14). Now you can handle file uploads.
```crystal ```crystal
post "/upload" do |env| post "/upload" do |env|
parse_multipart(env) do |field, data| parse_multipart(env) do |field, data|
image1 = data if field == "image1" image1 = data if field == "image1"
image2 = data if field == "image2" image2 = data if field == "image2"
"Upload complete" "Upload complete"
end end
end end
``` ```
- Make session configurable. Now you can specify session name and expire time with: - Make session configurable. Now you can specify session name and expire time with:
```crystal ```crystal
Kemal.config.session["name"] = "your_app" Kemal.config.session["name"] = "your_app"
Kemal.config.session["expire_time"] = 48.hours Kemal.config.session["expire_time"] = 48.hours
``` ```
- Session now supports more types. (`String`, `Int32`, `Float64`, `Bool`) - Session now supports more types. (`String`, `Int32`, `Float64`, `Bool`)
- Add `gzip` helper to enable / disable gzip compression on responses. - Add `gzip` helper to enable / disable gzip compression on responses.
@ -412,11 +406,11 @@ Kemal.config.session["expire_time"] = 48.hours
# 0.15.0 (03-09-2016) # 0.15.0 (03-09-2016)
- Add context store - Add context store.
- `KEMAL_ENV` respects to `Kemal.config.env` and needs to be explicitly set. - `KEMAL_ENV` respects to `Kemal.config.env` and needs to be explicitly set.
- `Kemal::InitHandler` is introduced. Adds initial configuration, headers like `X-Powered-By`. - `Kemal::InitHandler` is introduced. Adds initial configuration, headers like `X-Powered-By`.
- Add `send_file` to helpers. - Add `send_file` to helpers.
- Add mime types. - Add mime types.
- Fix parsing JSON params when "charset" is present in `Content-Type` header. - Fix parsing JSON params when "charset" is present in `Content-Type` header.
- Use http-only cookie for session - Use http-only cookie for session.
- Inject `STDOUT` by default in `CommonLogHandler` - Inject `STDOUT` by default in `CommonLogHandler`.