From 4a58bc9690b8c03de79c7437c79e65b897ee6edd Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Wed, 4 Jul 2018 21:42:58 +0300 Subject: [PATCH] Remove env.params.files and FileUpload --- src/kemal/file_upload.cr | 25 ------------------------- src/kemal/param_parser.cr | 18 ------------------ 2 files changed, 43 deletions(-) delete mode 100644 src/kemal/file_upload.cr diff --git a/src/kemal/file_upload.cr b/src/kemal/file_upload.cr deleted file mode 100644 index 562c18b..0000000 --- a/src/kemal/file_upload.cr +++ /dev/null @@ -1,25 +0,0 @@ -module Kemal - # :nodoc: - struct FileUpload - getter tmpfile : Tempfile - getter filename : String? - getter headers : HTTP::Headers - getter creation_time : Time? - getter modification_time : Time? - getter read_time : Time? - getter size : UInt64? - - def initialize(upload) - @tmpfile = Tempfile.new(filename) - ::File.open(@tmpfile.path, "w") do |file| - IO.copy(upload.body, file) - end - @filename = upload.filename - @headers = upload.headers - @creation_time = upload.creation_time - @modification_time = upload.modification_time - @read_time = upload.read_time - @size = upload.size - end - end -end diff --git a/src/kemal/param_parser.cr b/src/kemal/param_parser.cr index 18bf281..66626b4 100644 --- a/src/kemal/param_parser.cr +++ b/src/kemal/param_parser.cr @@ -9,13 +9,11 @@ module Kemal PARTS = %w(url query body json) # :nodoc: alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Any) | Array(JSON::Any) - getter files def initialize(@request : HTTP::Request, @url : Hash(String, String) = {} of String => String) @query = HTTP::Params.new({} of String => Array(String)) @body = HTTP::Params.new({} of String => Array(String)) @json = {} of String => AllParamTypes - @files = [] of FileUpload @url_parsed = false @query_parsed = false @body_parsed = false @@ -47,10 +45,6 @@ module Kemal @body = parse_part(@request.body) return end - if content_type.try(&.starts_with?(MULTIPART_FORM)) - parse_file_upload - return - end end private def parse_query @@ -61,18 +55,6 @@ module Kemal @url.each { |key, value| @url[key] = unescape_url_param(value) } end - private def parse_file_upload - HTTP::FormData.parse(@request) do |upload| - next unless upload - filename = upload.filename - if !filename.nil? - @files << FileUpload.new(upload: upload) - else - @body.add(upload.name, upload.body.gets_to_end) - end - end - end - # Parses JSON request body if Content-Type is `application/json`. # # - If request body is a JSON `Hash` then all the params are parsed and added into `params`.