lib/down/net_http.rb in down-5.2.4 vs lib/down/net_http.rb in down-5.3.0

- old
+ new

@@ -38,10 +38,11 @@ progress_proc = options.delete(:progress_proc) content_length_proc = options.delete(:content_length_proc) destination = options.delete(:destination) headers = options.delete(:headers) uri_normalizer = options.delete(:uri_normalizer) + extension = options.delete(:extension) # Use open-uri's :content_lenth_proc or :progress_proc to raise an # exception early if the file is too large. # # Also disable following redirects, as we'll provide our own @@ -91,11 +92,12 @@ end open_uri_file = open_uri(uri, open_uri_options, follows_remaining: max_redirects) # Handle the fact that open-uri returns StringIOs for small files. - tempfile = ensure_tempfile(open_uri_file, File.extname(open_uri_file.base_uri.path)) + extname = extension ? ".#{extension}" : File.extname(open_uri_file.base_uri.path) + tempfile = ensure_tempfile(open_uri_file, extname) OpenURI::Meta.init tempfile, open_uri_file # add back open-uri methods tempfile.extend Down::NetHttp::DownloadedFile download_result(tempfile, destination) end @@ -128,13 +130,10 @@ encoding: response.type_params["charset"], rewindable: options.fetch(:rewindable, true), on_close: -> { request.resume }, # close HTTP connnection data: { status: response.code.to_i, - headers: response.each_header.inject({}) { |headers, (downcased_name, value)| - name = downcased_name.split("-").map(&:capitalize).join("-") - headers.merge!(name => value) - }, + headers: normalize_headers(response.each_header), response: response, }, ) end