dassets 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dassets/server/response.rb +18 -13
- data/lib/dassets/version.rb +1 -1
- data/test/unit/server/response_tests.rb +44 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c88f5b13dbd9fd2f53e83907fee24cafab13103d25764d95461bb9c0f440c5411b698a94283eb06d870279bacde458e87f7b0ae363da0ea2a9579fb1ae4bd98
|
4
|
+
data.tar.gz: 874b87a5c52bbd3e3f47eb5f1b816f4c92e95ba7af6904a0811eaf51b815e101da59081e13b0ca01a23e1cb0b2df10d942d978a0d6a8505adee7933458a67f0c
|
5
5
|
SHA1:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/dassets/version.rb
CHANGED
@@ -182,7 +182,7 @@ class Dassets::Server::Response
|
|
182
182
|
|
183
183
|
end
|
184
184
|
|
185
|
-
class
|
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
|
-
|
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
|