From 740cb188a92ba33bc1d62257c0300eda505acdf3 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Fri, 30 Aug 2019 13:20:38 +0200 Subject: [PATCH 1/4] Check for KEMAL_ENV variable already in Config#initialize (#552) --- src/kemal/cli.cr | 25 +++++++++---------------- src/kemal/config.cr | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/kemal/cli.cr b/src/kemal/cli.cr index 656a4e6..b166708 100644 --- a/src/kemal/cli.cr +++ b/src/kemal/cli.cr @@ -8,7 +8,6 @@ module Kemal @key_file = "" @cert_file = "" @config = Kemal.config - read_env if args parse args end @@ -42,21 +41,15 @@ module Kemal private def configure_ssl {% if !flag?(:without_openssl) %} - if @ssl_enabled - abort "SSL Key Not Found" if !@key_file - abort "SSL Certificate Not Found" if !@cert_file - ssl = Kemal::SSL.new - ssl.key_file = @key_file.not_nil! - ssl.cert_file = @cert_file.not_nil! - Kemal.config.ssl = ssl.context - end - {% end %} - end - - private def read_env - if kemal_env = ENV["KEMAL_ENV"]? - @config.env = kemal_env - end + if @ssl_enabled + abort "SSL Key Not Found" if !@key_file + abort "SSL Certificate Not Found" if !@cert_file + ssl = Kemal::SSL.new + ssl.key_file = @key_file.not_nil! + ssl.cert_file = @cert_file.not_nil! + Kemal.config.ssl = ssl.context + end + {% end %} end end end diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 04bbdd7..2efcd66 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -29,7 +29,7 @@ module Kemal def initialize @host_binding = "0.0.0.0" @port = 3000 - @env = "development" + @env = ENV["KEMAL_ENV"]? || "development" @serve_static = {"dir_listing" => false, "gzip" => true} @public_folder = "./public" @logging = true From c893172fbf5fd036073046cc7ceb92e8b9eb6551 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Fri, 30 Aug 2019 13:32:23 +0200 Subject: [PATCH 2/4] Cleanup ameba warnings (#551) --- .ameba.yml | 31 +------------------------------ spec/helpers_spec.cr | 2 +- spec/run_spec.cr | 8 +++----- src/kemal/ext/response.cr | 1 + src/kemal/static_file_handler.cr | 1 + 5 files changed, 7 insertions(+), 36 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index cf5dbb2..9cc083d 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -1,5 +1,5 @@ # This configuration file was generated by `ameba --gen-config` -# on 2019-06-14 15:05:57 UTC using Ameba version 0.10.0. +# on 2019-08-25 09:29:24 UTC using Ameba version 0.10.0. # The point is for the user to remove these configuration records # one by one as the reported problems are removed from the code base. @@ -11,32 +11,3 @@ Lint/UselessAssign: Severity: Warning Excluded: - spec/view_spec.cr - -# Problems found: 1 -# Run `ameba --only Lint/ShadowingOuterLocalVar` for details -Lint/ShadowingOuterLocalVar: - Description: Disallows the usage of the same name as outer local variables for block - or proc arguments. - Enabled: true - Severity: Warning - Excluded: - - spec/run_spec.cr - -# Problems found: 1 -# Run `ameba --only Style/NegatedConditionsInUnless` for details -Style/NegatedConditionsInUnless: - Description: Disallows negated conditions in unless - Enabled: true - Severity: Convention - Excluded: - - src/kemal/ext/response.cr - -# Problems found: 1 -# Run `ameba --only Metrics/CyclomaticComplexity` for details -Metrics/CyclomaticComplexity: - Description: Disallows methods with a cyclomatic complexity higher than `MaxComplexity` - MaxComplexity: 10 - Enabled: true - Severity: Convention - Excluded: - - src/kemal/static_file_handler.cr diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr index 76fc318..4d45a66 100644 --- a/spec/helpers_spec.cr +++ b/spec/helpers_spec.cr @@ -70,7 +70,7 @@ describe "Macros" do halt env, status_code: 400, response: "Missing origin." end - get "/" do |env| + get "/" do |_env| "Hello world" end diff --git a/spec/run_spec.cr b/spec/run_spec.cr index 2553455..818cbe9 100644 --- a/spec/run_spec.cr +++ b/spec/run_spec.cr @@ -6,12 +6,10 @@ private def run(code) #{code} CR String.build do |stdout| - stderr = String.build do |stderr| - Process.new("crystal", ["eval"], input: IO::Memory.new(code), output: stdout, error: stderr).wait - end - unless stderr.empty? - fail(stderr) + stderr = String.build do |io| + Process.new("crystal", ["eval"], input: IO::Memory.new(code), output: stdout, error: io).wait end + fail(stderr) unless stderr.empty? end end diff --git a/src/kemal/ext/response.cr b/src/kemal/ext/response.cr index 1f0a8fd..faf9db1 100644 --- a/src/kemal/ext/response.cr +++ b/src/kemal/ext/response.cr @@ -1,6 +1,7 @@ class HTTP::Server::Response class Output def close + # ameba:disable Style/NegatedConditionsInUnless unless response.wrote_headers? && !response.headers.has_key?("Content-Range") response.content_length = @out_count end diff --git a/src/kemal/static_file_handler.cr b/src/kemal/static_file_handler.cr index cd83749..7f3e061 100644 --- a/src/kemal/static_file_handler.cr +++ b/src/kemal/static_file_handler.cr @@ -4,6 +4,7 @@ module Kemal class StaticFileHandler < HTTP::StaticFileHandler + # ameba:disable Metrics/CyclomaticComplexity def call(context : HTTP::Server::Context) return call_next(context) if context.request.path.not_nil! == "/" From a4bdecdc7d17a3fa705db4e1c3360590f836cb5d Mon Sep 17 00:00:00 2001 From: maggie Date: Fri, 11 Oct 2019 11:14:26 +0200 Subject: [PATCH 3/4] Flush io buffer after each write to log (#554) --- src/kemal/log_handler.cr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kemal/log_handler.cr b/src/kemal/log_handler.cr index fe902f2..ce08e57 100644 --- a/src/kemal/log_handler.cr +++ b/src/kemal/log_handler.cr @@ -8,11 +8,14 @@ module Kemal elapsed_time = Time.measure { call_next(context) } elapsed_text = elapsed_text(elapsed_time) @io << Time.utc << ' ' << context.response.status_code << ' ' << context.request.method << ' ' << context.request.resource << ' ' << elapsed_text << '\n' + @io.flush context end def write(message : String) @io << message + @io.flush + @io end private def elapsed_text(elapsed) From 4d6fb0614f29aa02254913dc6ed69b0cb148fa81 Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Sun, 1 Dec 2019 14:14:25 +0300 Subject: [PATCH 4/4] Bump version to 0.26.1 --- CHANGELOG.md | 8 ++++++++ shard.yml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2495569..d7d6b27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.26.1 (01-12-2019) + +- Fix process request when a response already closed [#550](https://github.com/kemalcr/kemal/pull/550). Thanks @mamantoha :pray: +- Switch to new Ameba repository [#549](https://github.com/kemalcr/kemal/pull/549). Thanks @mamantoha :pray: +- Check for `KEMAL_ENV` variable already in `Config#initialize`[#552](https://github.com/kemalcr/kemal/pull/552). Thanks @Sija :pray: +- Cleanup Ameba warnings [#551](https://github.com/kemalcr/kemal/pull/551). Thanks @Sija :pray: +- Flush io buffer after each write to log [#554](https://github.com/kemalcr/kemal/pull/554). Thanks @mang :pray: + # 0.26.0 (05-08-2019) - Crystal 0.30.0 support :tada: [#548](https://github.com/kemalcr/kemal/pull/548) and [#544](https://github.com/kemalcr/kemal/pull/544). Thanks @bcardiff and @straight-shoota :pray: diff --git a/shard.yml b/shard.yml index b1629b1..d605e2c 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: kemal -version: 0.26.0 +version: 0.26.1 authors: - Serdar Dogruyol