Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Luna 2019-08-04 22:42:22 -03:00
commit 1a8894eece
9 changed files with 61 additions and 13 deletions

42
.ameba.yml Normal file
View File

@ -0,0 +1,42 @@
# This configuration file was generated by `ameba --gen-config`
# on 2019-06-14 15:05:57 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.
# Problems found: 7
# Run `ameba --only Lint/UselessAssign` for details
Lint/UselessAssign:
Description: Disallows useless variable assignments
Enabled: true
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

4
.gitignore vendored
View File

@ -2,7 +2,7 @@
/.crystal/
/.shards/
*.log
/bin/
# Libraries don't need dependency lock
# Dependencies will be locked in application that uses them
/shard.lock
/shard.lock

View File

@ -7,6 +7,7 @@ script:
- crystal spec
- crystal spec --release --no-debug
- crystal tool format --check
- bin/ameba src
matrix:
allow_failures:

View File

@ -15,6 +15,11 @@ dependencies:
github: crystal-loot/exception_page
version: ~> 0.1.1
development_dependencies:
ameba:
github: veelenga/ameba
version: ~> 0.10.0
crystal: 0.27.2
license: MIT

View File

@ -14,7 +14,7 @@ module Kemal
log("Exception: #{ex.inspect_with_backtrace}")
return call_exception_with_status_code(context, ex, 500) if Kemal.config.error_handlers.has_key?(500)
verbosity = Kemal.config.env == "production" ? false : true
return render_500(context, ex, verbosity)
render_500(context, ex, verbosity)
end
private def call_exception_with_status_code(context : HTTP::Server::Context, exception : Exception, status_code : Int32)

File diff suppressed because one or more lines are too long

View File

@ -184,26 +184,26 @@ end
private def multipart(file, env : HTTP::Server::Context)
# See http://httpwg.org/specs/rfc7233.html
fileb = file.size
startb = endb = 0
startb = endb = 0_i64
if match = env.request.headers["Range"].match /bytes=(\d{1,})-(\d{0,})/
startb = match[1].to_i { 0 } if match.size >= 2
endb = match[2].to_i { 0 } if match.size >= 3
startb = match[1].to_i64 { 0_i64 } if match.size >= 2
endb = match[2].to_i64 { 0_i64 } if match.size >= 3
end
endb = fileb - 1 if endb == 0
if startb < endb < fileb
content_length = 1 + endb - startb
content_length = 1_i64 + endb - startb
env.response.status_code = 206
env.response.content_length = content_length
env.response.headers["Accept-Ranges"] = "bytes"
env.response.headers["Content-Range"] = "bytes #{startb}-#{endb}/#{fileb}" # MUST
if startb > 1024
skipped = 0
skipped = 0_i64
# file.skip only accepts values less or equal to 1024 (buffer size, undocumented)
until (increase_skipped = skipped + 1024) > startb
until (increase_skipped = skipped + 1024_i64) > startb
file.skip(1024)
skipped = increase_skipped
end

View File

@ -24,7 +24,7 @@ module Kemal
end
private def unescape_url_param(value : String)
value.empty? ? value : URI.unescape(value)
value.empty? ? value : URI.decode(value)
rescue
value
end

View File

@ -21,7 +21,7 @@ module Kemal
config = Kemal.config.serve_static
original_path = context.request.path.not_nil!
request_path = URI.unescape(original_path)
request_path = URI.decode(original_path)
# File path cannot contains '\0' (NUL) because all filesystem I know
# don't accept '\0' character as file name.
@ -52,7 +52,7 @@ module Kemal
context.response.content_type = "text/html"
directory_listing(context.response, request_path, file_path)
else
return call_next(context)
call_next(context)
end
elsif File.exists?(file_path)
last_modified = modification_time(file_path)