dassets 0.13.1 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA512:
3
- metadata.gz: 7402d80d36dfa89d1f68c64a739ffbc516eb1901694e9638ee930835f8b68807fa8dd56245265f8c68af4719633d4b273f13c67ff744f60904f66c5ec27231c5
4
- data.tar.gz: 657e6338f28159a89ef32225be168b3ca03379b26b73a6db01f0f3b0c0b11a01c3659286185d9d01471dc06aadcb308cbd51700ccf8bdfd0f0261f358fa9f27a
3
+ metadata.gz: 6c88f5b13dbd9fd2f53e83907fee24cafab13103d25764d95461bb9c0f440c5411b698a94283eb06d870279bacde458e87f7b0ae363da0ea2a9579fb1ae4bd98
4
+ data.tar.gz: 874b87a5c52bbd3e3f47eb5f1b816f4c92e95ba7af6904a0811eaf51b815e101da59081e13b0ca01a23e1cb0b2df10d942d978a0d6a8505adee7933458a67f0c
5
5
  SHA1:
6
- metadata.gz: 98e6907a11c2dc4e0409f14c0361094ecffa8396
7
- data.tar.gz: fafaeb2c34ac116922f469b2ec7317f2688de99e
6
+ metadata.gz: 77e8957bf984a1b6957afee6fbb99d370a9752af
7
+ data.tar.gz: bf20c13e61aeccabed7110b6eb630fbfc933d0a6
@@ -47,19 +47,7 @@ class Dassets::Server
47
47
 
48
48
  def initialize(env, asset_file)
49
49
  @asset_file = asset_file
50
-
51
- content_size = @asset_file.size
52
- ranges = Rack::Utils.byte_ranges(env, content_size)
53
- if ranges.nil? || ranges.empty? || ranges.length > 1
54
- # No ranges or multiple ranges are not supported
55
- @range = 0..content_size-1
56
- @content_range = nil
57
- else
58
- # single range
59
- @range = ranges[0]
60
- @content_range = "bytes #{@range.begin}-#{@range.end}/#{content_size}"
61
- end
62
-
50
+ @range, @content_range = get_range_info(env, @asset_file)
63
51
  @size = self.range_end - self.range_begin + 1
64
52
  end
65
53
 
@@ -96,6 +84,23 @@ class Dassets::Server
96
84
  self.range_end == other_body.range_end
97
85
  end
98
86
 
87
+ private
88
+
89
+ def get_range_info(env, asset_file)
90
+ content_size = asset_file.size
91
+ # legacy rack version, just return full size
92
+ return full_size_range_info(content_size) if !Rack::Utils.respond_to?(:byte_ranges)
93
+ ranges = Rack::Utils.byte_ranges(env, content_size)
94
+ # No ranges or multiple ranges are not supported, just return full size
95
+ return full_size_range_info(content_size) if ranges.nil? || ranges.empty? || ranges.length > 1
96
+ # single range
97
+ [ranges[0], "bytes #{ranges[0].begin}-#{ranges[0].end}/#{content_size}"]
98
+ end
99
+
100
+ def full_size_range_info(content_size)
101
+ [(0..content_size-1), nil]
102
+ end
103
+
99
104
  end
100
105
 
101
106
  end
@@ -1,3 +1,3 @@
1
1
  module Dassets
2
- VERSION = "0.13.1"
2
+ VERSION = "0.13.2"
3
3
  end
@@ -182,7 +182,7 @@ class Dassets::Server::Response
182
182
 
183
183
  end
184
184
 
185
- class PartialBodyTests < BodyIOTests
185
+ class PartialBodySetupTests < BodyIOTests
186
186
  desc "for a partial content request"
187
187
  setup do
188
188
  @start_chunk = Factory.boolean ? 0 : 1
@@ -191,8 +191,14 @@ class Dassets::Server::Response
191
191
  @partial_size = @partial_chunks * Body::CHUNK_SIZE
192
192
  @partial_end = @partial_begin + (@partial_size-1)
193
193
 
194
- env = { 'HTTP_RANGE' => "bytes=#{@partial_begin}-#{@partial_end}" }
195
- @body = Body.new(env, @asset_file)
194
+ @env = { 'HTTP_RANGE' => "bytes=#{@partial_begin}-#{@partial_end}" }
195
+ end
196
+
197
+ end
198
+
199
+ class PartialBodyTests < PartialBodySetupTests
200
+ setup do
201
+ @body = Body.new(@env, @asset_file)
196
202
  end
197
203
  subject{ @body }
198
204
 
@@ -227,4 +233,39 @@ class Dassets::Server::Response
227
233
 
228
234
  end
229
235
 
236
+ class LegacyRackTests < PartialBodySetupTests
237
+ desc "when using a legacy version of rack that can't interpret byte ranges"
238
+ setup do
239
+ Assert.stub(Rack::Utils, :respond_to?).with(:byte_ranges){ false }
240
+ @body = Body.new(@env, @asset_file)
241
+ end
242
+
243
+ should "not be partial" do
244
+ assert_false subject.partial?
245
+ end
246
+
247
+ should "be the full content size" do
248
+ assert_equal @asset_file.size, subject.size
249
+ end
250
+
251
+ should "have no content range" do
252
+ assert_nil subject.content_range
253
+ end
254
+
255
+ should "have the full content size as its range" do
256
+ assert_equal 0, subject.range_begin
257
+ assert_equal subject.size-1, subject.range_end
258
+ end
259
+
260
+ should "chunk the full content when iterated" do
261
+ chunks = []
262
+ subject.each{ |chunk| chunks << chunk }
263
+
264
+ assert_equal @num_chunks, chunks.size
265
+ assert_equal subject.class::CHUNK_SIZE, chunks.first.size
266
+ assert_equal @asset_file.content, chunks.join('')
267
+ end
268
+
269
+ end
270
+
230
271
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dassets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding