format_parser 0.29.0 → 0.29.1
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/CHANGELOG.md +3 -0
- data/lib/format_parser/version.rb +1 -1
- data/lib/remote_io.rb +19 -5
- data/spec/remote_fetching_spec.rb +23 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75ee83f55840e3031d4d60d8dc07ca038812188613e2b740079e1c965efb2886
|
4
|
+
data.tar.gz: 31c3ee84434560c18e6ea74a23160b909e6f880f52b2ed6f0e888e847c557bd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 536cfb1bac7926f56ba760959d7c5a0905d3b2b0944b16248b6c81be00b722dad894a8d6d5773134fb0471e42d016a20be15e3d5a01c671f0cc65658f2fc05b4
|
7
|
+
data.tar.gz: cb3f73df051b8612cb6d0e1a4e55c045e461bf2c5e4667dd6e461e779b1f39d01be8d70d084e252e5198a966ac590129286811f5822808a0c980c2ad72a087a1
|
data/CHANGELOG.md
CHANGED
data/lib/remote_io.rb
CHANGED
@@ -89,18 +89,32 @@ class FormatParser::RemoteIO
|
|
89
89
|
response = conn.get(@uri, nil, range: 'bytes=%d-%d' % [range.begin, range.end])
|
90
90
|
|
91
91
|
case response.status
|
92
|
-
when 200
|
92
|
+
when 200
|
93
|
+
# S3 returns 200 when you request a Range that is fully satisfied by the entire object,
|
94
|
+
# we take that into account here. Also, for very tiny responses (and also for empty responses)
|
95
|
+
# the responses are going to be 200 which does not mean we cannot proceed
|
96
|
+
# To have a good check for both of these conditions we need to know whether the ranges overlap fully
|
97
|
+
response_size = response.body.bytesize
|
98
|
+
requested_range_size = range.end - range.begin + 1
|
99
|
+
if response_size > requested_range_size
|
100
|
+
error_message = [
|
101
|
+
"We requested #{requested_range_size} bytes, but the server sent us more",
|
102
|
+
"(#{response_size} bytes) - it likely has no `Range:` support.",
|
103
|
+
"The error occurred when talking to #{@uri})"
|
104
|
+
]
|
105
|
+
raise InvalidRequest.new(response.status, error_message.join("\n"))
|
106
|
+
end
|
107
|
+
[response_size, response.body]
|
108
|
+
when 206
|
93
109
|
# Figure out of the server supports content ranges, if it doesn't we have no
|
94
110
|
# business working with that server
|
95
111
|
range_header = response.headers['Content-Range']
|
96
|
-
raise InvalidRequest.new(response.status, "
|
112
|
+
raise InvalidRequest.new(response.status, "The server replied with 206 status but no Content-Range at #{@uri}") unless range_header
|
97
113
|
|
98
114
|
# "Content-Range: bytes 0-0/307404381" is how the response header is structured
|
99
115
|
size = range_header[/\/(\d+)$/, 1].to_i
|
100
116
|
|
101
|
-
#
|
102
|
-
# we take that into account here. For other servers, 206 is the expected response code.
|
103
|
-
# Also, if we request a _larger_ range than what can be satisfied by the server,
|
117
|
+
# If we request a _larger_ range than what can be satisfied by the server,
|
104
118
|
# the response is going to only contain what _can_ be sent and the status is also going
|
105
119
|
# to be 206
|
106
120
|
return [size, response.body]
|
@@ -19,18 +19,27 @@ describe 'Fetching data from HTTP remotes' do
|
|
19
19
|
res.status = 302
|
20
20
|
res.header['Location'] = req.path.sub('/redirect', '')
|
21
21
|
end
|
22
|
+
@server.mount_proc '/empty' do |_req, res|
|
23
|
+
res.status = 200
|
24
|
+
res.body = ''
|
25
|
+
end
|
26
|
+
@server.mount_proc '/tiny' do |_req, res|
|
27
|
+
res.status = 200
|
28
|
+
res.body = File.read(fixtures_dir + '/test.gif')
|
29
|
+
end
|
30
|
+
|
22
31
|
trap('INT') { @server.stop }
|
23
32
|
@server_thread = Thread.new { @server.start }
|
24
33
|
end
|
25
34
|
|
26
|
-
it '
|
35
|
+
it 'works with .parse_http called without any options' do
|
27
36
|
result = FormatParser.parse_http('http://localhost:9399/PNG/anim.png')
|
28
37
|
|
29
38
|
expect(result.format).to eq(:png)
|
30
39
|
expect(result.height_px).to eq(180)
|
31
40
|
end
|
32
41
|
|
33
|
-
it '
|
42
|
+
it 'works with .parse_http called with additional options' do
|
34
43
|
fake_result = double(nature: :audio, format: :aiff)
|
35
44
|
expect_any_instance_of(FormatParser::AIFFParser).to receive(:call).and_return(fake_result)
|
36
45
|
results = FormatParser.parse_http('http://localhost:9399/PNG/anim.png', results: :all)
|
@@ -39,6 +48,18 @@ describe 'Fetching data from HTTP remotes' do
|
|
39
48
|
expect(results).to include(fake_result)
|
40
49
|
end
|
41
50
|
|
51
|
+
it 'is able to cope with a 0-size resource which does not provide Content-Range' do
|
52
|
+
file_information = FormatParser.parse_http('http://localhost:9399/empty')
|
53
|
+
|
54
|
+
expect(file_information).to be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'is able to cope with a tiny resource which fits into the first requested range completely' do
|
58
|
+
file_information = FormatParser.parse_http('http://localhost:9399/tiny')
|
59
|
+
expect(file_information).not_to be_nil
|
60
|
+
expect(file_information.nature).to eq(:image)
|
61
|
+
end
|
62
|
+
|
42
63
|
it 'parses the animated PNG over HTTP' do
|
43
64
|
file_information = FormatParser.parse_http('http://localhost:9399/PNG/anim.png')
|
44
65
|
expect(file_information).not_to be_nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: format_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.29.
|
4
|
+
version: 0.29.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Berman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ks
|