down 2.3.7 → 2.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/down.gemspec +1 -0
  3. data/lib/down.rb +24 -5
  4. data/lib/down/version.rb +1 -1
  5. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a627a73d7e6160d9dba196fbfc3abbcebcff7487
4
- data.tar.gz: 9bc58d0030ef83a3c0eaa3d05c560d912917f15f
3
+ metadata.gz: eb93603bdd669c579229eed4924173323351f338
4
+ data.tar.gz: 985886e895e1c71328d812df17990c944efe8cb1
5
5
  SHA512:
6
- metadata.gz: 42d20a8bd55512edab25ac2c7679503069c26f248adef49c9d50b1da0f23a15e14f6d0a182bd88dea121bd7e2f3191699aa3a13619639be13a7b08ed7bcf450c
7
- data.tar.gz: 834d4189e69863ffa826ec82ba3eb721811570548f8251737667eee386b196a53c7d9eaf5a0bd47ae0da7aaf869e60d51b2124443dbb40f19e901a28eb93f877
6
+ metadata.gz: 03935d502e94f8a8b681996aa364f13cdee50c84cdc2b9655df2146d31a263bb2319280e9636cef90b8a70f59f5d80004e5ed0620af5085c72e9ed435391b430
7
+ data.tar.gz: bcb236b7447b47674c2adcf72047ca37f904f2507ba27e297db60c3869e7728d36b79b0be5f63132c5e9f5227f20fdabfe00bed95fa65e4681501e94df87c8a5
@@ -16,5 +16,6 @@ Gem::Specification.new do |spec|
16
16
  spec.add_development_dependency "rake"
17
17
  spec.add_development_dependency "minitest", "~> 5.8"
18
18
  spec.add_development_dependency "webmock"
19
+ spec.add_development_dependency "addressable", "< 2.5"
19
20
  spec.add_development_dependency "mocha"
20
21
  end
@@ -116,11 +116,30 @@ module Down
116
116
 
117
117
  response = request.resume
118
118
 
119
- ChunkedIO.new(
120
- chunks: response.enum_for(:read_body),
121
- size: response["Content-Length"] && response["Content-Length"].to_i,
122
- on_close: -> { request.resume },
123
- )
119
+ if response.chunked?
120
+ # Net::HTTP's implementation of reading "Transfer-Encoding: chunked"
121
+ # raises a Fiber error, so we work around it by downloading the whole
122
+ # response body without Enumerators (which internally use Fibers).
123
+ warn "Response from #{url} returned as \"Transfer-Encoding: chunked\", which Down cannot partially download, so the whole response body will be downloaded instead."
124
+
125
+ tempfile = Tempfile.new("down", binmode: true)
126
+ response.read_body { |chunk| tempfile << chunk }
127
+ tempfile.rewind
128
+
129
+ request.resume # close HTTP connection
130
+
131
+ ChunkedIO.new(
132
+ chunks: Enumerator.new { |y| y << tempfile.read(16*1024) until tempfile.eof? },
133
+ size: tempfile.size,
134
+ on_close: -> { tempfile.close! },
135
+ )
136
+ else
137
+ ChunkedIO.new(
138
+ chunks: response.enum_for(:read_body),
139
+ size: response["Content-Length"] && response["Content-Length"].to_i,
140
+ on_close: -> { request.resume }, # close HTTP connnection
141
+ )
142
+ end
124
143
  end
125
144
 
126
145
  def copy_to_tempfile(basename, io)
@@ -1,3 +1,3 @@
1
1
  module Down
2
- VERSION = "2.3.7"
2
+ VERSION = "2.3.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: down
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.7
4
+ version: 2.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-06 00:00:00.000000000 Z
11
+ date: 2016-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: addressable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "<"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: mocha
57
71
  requirement: !ruby/object:Gem::Requirement