Compare commits
9 commits
bcf875b1d8
...
1a8894eece
Author | SHA1 | Date | |
---|---|---|---|
1a8894eece | |||
|
18ddc3b4e6 | ||
|
17bf1c7709 | ||
|
6e2714404d | ||
|
e3544a86bf | ||
|
f3d02e60af | ||
|
fc8ac1160c | ||
|
ecaa423774 | ||
|
06665e81bc |
9 changed files with 61 additions and 13 deletions
42
.ameba.yml
Normal file
42
.ameba.yml
Normal 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
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -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
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue