format_parser 2.0.0.pre.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -2
- data/lib/format_parser/version.rb +1 -1
- data/lib/remote_io.rb +4 -4
- data/spec/remote_io_spec.rb +33 -8
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b7ea3319eba27d70e1945f6e8584e978a0e7b61b225fb651ad9d0e6daa649e0
|
4
|
+
data.tar.gz: 58c7ad6d34d8271cadad852cffcbdc252ba4b1ee2c0d0ac0d55d739845b7f2a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7a5d3416c8f9aa1a58243ca183a3c0014979a6bfba4852fdbf7e46cc2b2bd5486160437b4db66ad39d64525324fb120bdca25928bbfcfef59ec57959ab22727
|
7
|
+
data.tar.gz: 829b4fb1d543691d1a7ca284eb21ab9238d101bc750399402034eaab39f87505eeee3d57a92eb15eede37d6176094b94d70fe21f2066f7b1ed2ecf22f57ccac8
|
data/CHANGELOG.md
CHANGED
data/lib/remote_io.rb
CHANGED
@@ -103,12 +103,12 @@ class FormatParser::RemoteIO
|
|
103
103
|
# @param uri[URI] The URI to fetch from
|
104
104
|
# @param redirects[Integer] The amount of remaining permitted redirects
|
105
105
|
# @return [[Integer, String]] The response body of the ranged request
|
106
|
-
def request_range(range, uri = @uri, redirects = REDIRECT_LIMIT)
|
106
|
+
def request_range(range, uri = @uri, headers = @headers.clone, redirects = REDIRECT_LIMIT)
|
107
107
|
# We use a GET and not a HEAD request followed by a GET because
|
108
108
|
# S3 does not allow HEAD requests if you only presigned your URL for GETs, so we
|
109
109
|
# combine the first GET of a segment and retrieving the size of the resource
|
110
110
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
111
|
-
http.request_get(uri,
|
111
|
+
http.request_get(uri, headers.merge({ 'range' => 'bytes=%d-%d' % [range.begin, range.end] }))
|
112
112
|
end
|
113
113
|
case response
|
114
114
|
when Net::HTTPOK
|
@@ -146,8 +146,8 @@ class FormatParser::RemoteIO
|
|
146
146
|
if location
|
147
147
|
new_uri = redirect_uri(location, uri)
|
148
148
|
# Clear the Authorization header if the new URI has a different host.
|
149
|
-
|
150
|
-
request_range(range, new_uri, redirects - 1)
|
149
|
+
headers.delete('Authorization') unless [uri.scheme, uri.host, uri.port] == [new_uri.scheme, new_uri.host, new_uri.port]
|
150
|
+
request_range(range, new_uri, headers, redirects - 1)
|
151
151
|
else
|
152
152
|
raise InvalidRequest.new(response.code, "Server at #{uri} replied with a #{response.code}, indicating redirection; however, the location header was empty.")
|
153
153
|
end
|
data/spec/remote_io_spec.rb
CHANGED
@@ -17,9 +17,8 @@ describe FormatParser::RemoteIO do
|
|
17
17
|
|
18
18
|
rio = described_class.new(url)
|
19
19
|
rio.seek(10)
|
20
|
-
read_result = rio.read(100)
|
21
20
|
|
22
|
-
expect(
|
21
|
+
expect(rio.read(100)).to eq(body)
|
23
22
|
expect(stub).to have_been_requested
|
24
23
|
end
|
25
24
|
end
|
@@ -58,9 +57,8 @@ describe FormatParser::RemoteIO do
|
|
58
57
|
|
59
58
|
rio = described_class.new(url)
|
60
59
|
rio.seek(10)
|
61
|
-
read_result = rio.read(100)
|
62
60
|
|
63
|
-
expect(
|
61
|
+
expect(rio.read(100)).to eq(body)
|
64
62
|
expect(stub).to have_been_requested
|
65
63
|
end
|
66
64
|
|
@@ -119,9 +117,37 @@ describe FormatParser::RemoteIO do
|
|
119
117
|
|
120
118
|
rio = described_class.new(redirecting_url, headers: { 'Authorization' => 'token' })
|
121
119
|
rio.seek(10)
|
122
|
-
read_result = rio.read(100)
|
123
120
|
|
124
|
-
expect(
|
121
|
+
expect(rio.read(100)).to eq(body)
|
122
|
+
expect(redirect_stub).to have_been_requested
|
123
|
+
expect(destination_stub).to have_been_requested
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'subsequent reads by the same object keep the Authorization header' do
|
127
|
+
redirecting_url = 'https://my_images.invalid/my_image'
|
128
|
+
destination_url = 'https://images.invalid/img.jpg'
|
129
|
+
body = 'response body'
|
130
|
+
auth_header = { 'Authorization' => 'token' }
|
131
|
+
|
132
|
+
redirect_stub = stub_request(:get, redirecting_url)
|
133
|
+
.with(headers: auth_header)
|
134
|
+
.to_return(headers: { 'location' => destination_url }, status: code)
|
135
|
+
destination_stub = stub_request(:get, destination_url)
|
136
|
+
.with { |request| !request.headers.key?('Authorization') }
|
137
|
+
.to_return(body: body, status: 200)
|
138
|
+
|
139
|
+
rio = described_class.new(redirecting_url, headers: auth_header)
|
140
|
+
rio.seek(10)
|
141
|
+
rio.read(100)
|
142
|
+
|
143
|
+
expect(redirect_stub).to have_been_requested
|
144
|
+
expect(destination_stub).to have_been_requested
|
145
|
+
|
146
|
+
WebMock.reset_executed_requests!
|
147
|
+
|
148
|
+
rio.seek(10)
|
149
|
+
|
150
|
+
expect(rio.read(100)).to eq(body)
|
125
151
|
expect(redirect_stub).to have_been_requested
|
126
152
|
expect(destination_stub).to have_been_requested
|
127
153
|
end
|
@@ -145,9 +171,8 @@ describe FormatParser::RemoteIO do
|
|
145
171
|
|
146
172
|
rio = described_class.new(redirecting_url, headers: { 'Authorization' => 'token' })
|
147
173
|
rio.seek(10)
|
148
|
-
read_result = rio.read(100)
|
149
174
|
|
150
|
-
expect(
|
175
|
+
expect(rio.read(100)).to eq(body)
|
151
176
|
expect(redirect_stub).to have_been_requested
|
152
177
|
expect(destination_stub).to have_been_requested
|
153
178
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: format_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Berman
|
8
8
|
- Julik Tarkhanov
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-11-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: exifr
|
@@ -287,7 +287,7 @@ licenses:
|
|
287
287
|
- MIT (Hippocratic)
|
288
288
|
metadata:
|
289
289
|
allowed_push_host: https://rubygems.org
|
290
|
-
post_install_message:
|
290
|
+
post_install_message:
|
291
291
|
rdoc_options: []
|
292
292
|
require_paths:
|
293
293
|
- lib
|
@@ -298,12 +298,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
298
298
|
version: '0'
|
299
299
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
300
300
|
requirements:
|
301
|
-
- - "
|
301
|
+
- - ">="
|
302
302
|
- !ruby/object:Gem::Version
|
303
|
-
version:
|
303
|
+
version: '0'
|
304
304
|
requirements: []
|
305
|
-
rubygems_version: 3.
|
306
|
-
signing_key:
|
305
|
+
rubygems_version: 3.3.7
|
306
|
+
signing_key:
|
307
307
|
specification_version: 4
|
308
308
|
summary: A library for efficient parsing of file metadata
|
309
309
|
test_files: []
|