format_parser 2.0.0.pre.3 → 2.0.0.pre.4

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
  SHA256:
3
- metadata.gz: 898819bf7d61150f2e0ac11f880c4b36478e8ddd66d05631f844cd70515d168b
4
- data.tar.gz: 9a0566ad6de66342ce88c3252ed2783eae2eda23180cd752bbef793fd9797499
3
+ metadata.gz: 296574f6c5b3d83cc13a222c9169eb1a0a53be4fd2bb28b08b72dab34cc3188f
4
+ data.tar.gz: 4d53f0a86a9361dc47263373e0f2169c2d6678848dd08d32cd826a8a4f198b50
5
5
  SHA512:
6
- metadata.gz: 11a3e410f40f932d913bff00abd57f8f359e59ae44f648347dd565258589a3dabf263a0e076496cf2b47ee3902cf352e927d4eb3c8a7913fd699b86c379a9fc9
7
- data.tar.gz: 24dde163c2074129e7896de322d53bf52dbb57a0b4d3db0db270e55b2c0bea5661f862a9f44e1c24953746f9629de78e3eeef7b9fe03db36690d9697a55ae0a7
6
+ metadata.gz: 9a8da6c14b682c38cbf491a013fb8c52a65f27ac8ae3f144e3c3eb88d95903b888fa69607f5e3d32b1b5aa8d0f76d369e0d42eed2841616e42e30a82103940cf
7
+ data.tar.gz: 49921898b361c4655a61cb7c3ef06fa2bc1eb94e0203088c6965c4dd0bd2b24436d33e59597696b9fa272eeb4f75d29d2b6c545fbb5bdcb950991f3e1b41a6b3
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '2.0.0.pre.3'
2
+ VERSION = '2.0.0.pre.4'
3
3
  end
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, @headers.merge({ 'range' => 'bytes=%d-%d' % [range.begin, range.end] }))
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
- @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, 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
@@ -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(read_result).to eq(body)
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(read_result).to eq(body)
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(read_result).to eq(body)
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(read_result).to eq(body)
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.3
4
+ version: 2.0.0.pre.4
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: 2022-10-31 00:00:00.000000000 Z
12
+ date: 2022-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: exifr