Compare commits

..

9 commits

Author SHA1 Message Date
1a8894eece Merge remote-tracking branch 'upstream/master' 2019-08-04 22:42:22 -03:00
Omar Roth
18ddc3b4e6 Fix static file handler for files > 2^31 bytes (#546) 2019-08-03 19:37:23 +03:00
Brian J. Cardiff
17bf1c7709 Upgrade to Crystal v0.30.0 (#548) 2019-08-03 19:35:40 +03:00
Johannes Müller
6e2714404d Add missing return types to overrides of abstract methods (#544) 2019-07-26 11:48:14 +03:00
Anton Maminov
e3544a86bf Do not early return from HTTP::Server::Response::Output.close. Revert what Ameba broke 2019-06-18 18:03:32 +03:00
sdogruyol
f3d02e60af Add auto-generated .ameba.yml 2019-06-13 15:42:21 +03:00
sdogruyol
fc8ac1160c Add /bin to .gitignore 2019-06-13 15:33:11 +03:00
sdogruyol
ecaa423774 Bump ameba to 0.10.0 2019-06-13 14:38:41 +03:00
Sijawusz Pur Rahnama
06665e81bc Use Ameba on Travis CI (#520) 2019-06-13 14:31:45 +03:00
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/ /.crystal/
/.shards/ /.shards/
*.log *.log
/bin/
# Libraries don't need dependency lock # Libraries don't need dependency lock
# Dependencies will be locked in application that uses them # Dependencies will be locked in application that uses them
/shard.lock /shard.lock

View file

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

View file

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

View file

@ -14,7 +14,7 @@ module Kemal
log("Exception: #{ex.inspect_with_backtrace}") log("Exception: #{ex.inspect_with_backtrace}")
return call_exception_with_status_code(context, ex, 500) if Kemal.config.error_handlers.has_key?(500) return call_exception_with_status_code(context, ex, 500) if Kemal.config.error_handlers.has_key?(500)
verbosity = Kemal.config.env == "production" ? false : true verbosity = Kemal.config.env == "production" ? false : true
return render_500(context, ex, verbosity) render_500(context, ex, verbosity)
end end
private def call_exception_with_status_code(context : HTTP::Server::Context, exception : Exception, status_code : Int32) 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) private def multipart(file, env : HTTP::Server::Context)
# See http://httpwg.org/specs/rfc7233.html # See http://httpwg.org/specs/rfc7233.html
fileb = file.size fileb = file.size
startb = endb = 0 startb = endb = 0_i64
if match = env.request.headers["Range"].match /bytes=(\d{1,})-(\d{0,})/ if match = env.request.headers["Range"].match /bytes=(\d{1,})-(\d{0,})/
startb = match[1].to_i { 0 } if match.size >= 2 startb = match[1].to_i64 { 0_i64 } if match.size >= 2
endb = match[2].to_i { 0 } if match.size >= 3 endb = match[2].to_i64 { 0_i64 } if match.size >= 3
end end
endb = fileb - 1 if endb == 0 endb = fileb - 1 if endb == 0
if startb < endb < fileb if startb < endb < fileb
content_length = 1 + endb - startb content_length = 1_i64 + endb - startb
env.response.status_code = 206 env.response.status_code = 206
env.response.content_length = content_length env.response.content_length = content_length
env.response.headers["Accept-Ranges"] = "bytes" env.response.headers["Accept-Ranges"] = "bytes"
env.response.headers["Content-Range"] = "bytes #{startb}-#{endb}/#{fileb}" # MUST env.response.headers["Content-Range"] = "bytes #{startb}-#{endb}/#{fileb}" # MUST
if startb > 1024 if startb > 1024
skipped = 0 skipped = 0_i64
# file.skip only accepts values less or equal to 1024 (buffer size, undocumented) # 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) file.skip(1024)
skipped = increase_skipped skipped = increase_skipped
end end

View file

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

View file

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