From 4330e85b1712f15a4a0333b2dde4e23cb5e17f2b Mon Sep 17 00:00:00 2001 From: Peter Graham Date: Fri, 22 Feb 2013 23:07:34 -0800 Subject: [PATCH] Support HTTPS in Downloads::File#http_get_streaming --- app/logical/downloads/file.rb | 6 +++--- test/unit/downloads/file_test.rb | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/logical/downloads/file.rb b/app/logical/downloads/file.rb index e77e6d0a7..85bdd529b 100644 --- a/app/logical/downloads/file.rb +++ b/app/logical/downloads/file.rb @@ -41,8 +41,8 @@ module Downloads limit = 4 while true - unless url.is_a?(URI::HTTP) - raise Error.new("URL must be HTTP") + unless url.is_a?(URI::HTTP) || url.is_a?(URI::HTTPS) + raise Error.new("URL must be HTTP or HTTPS") end headers = { @@ -50,7 +50,7 @@ module Downloads } @source, headers = before_download(source, headers) - Net::HTTP.start(url.host, url.port) do |http| + Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http| http.read_timeout = 10 http.request_get(url.request_uri, headers) do |res| case res diff --git a/test/unit/downloads/file_test.rb b/test/unit/downloads/file_test.rb index efac1cee2..24fd99a29 100644 --- a/test/unit/downloads/file_test.rb +++ b/test/unit/downloads/file_test.rb @@ -39,5 +39,24 @@ module Downloads assert_match(/image\/gif/, @download.content_type) end end + + context "A post download with an HTTPS source" do + setup do + @source = "https://www.google.com/intl/en_ALL/images/logo.gif" + @tempfile = Tempfile.new("danbooru-test") + @download = Downloads::File.new(@source, @tempfile.path) + end + + teardown do + @tempfile.close + end + + should "stream a file from an HTTPS source" do + @download.http_get_streaming do |resp| + assert_equal("200", resp.code) + assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes") + end + end + end end end