format_parser 0.28.0 → 0.29.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 +3 -0
- data/lib/format_parser.rb +3 -2
- data/lib/format_parser/version.rb +1 -1
- data/lib/remote_io.rb +4 -2
- data/spec/remote_fetching_spec.rb +19 -0
- 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: b8efef8742cfefdcde0aa05ab32c726004325c2210b19e25ca2cf866ad786074
|
4
|
+
data.tar.gz: bbd59f6f046a35cff93ea4e20a5168c2912007b06b3fabe7a5b23f7a0ed70c34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4a7d965be6ff0cb0abf8cdec5f4d31259aada155ae465c1b31d5eba718f9d0071ee8b7a6b2061e6024add45d32b901c0f95a37373727a59fd4a6562041f52e9
|
7
|
+
data.tar.gz: d314cb6876185ddedcef01c67205cf0635c2d8aebd0871dfd7834f0f54c15c38c31db7cc730c6aea8f8a72aff85949fa6937d970dfb320120a5b8c843f003753
|
data/CHANGELOG.md
CHANGED
data/lib/format_parser.rb
CHANGED
@@ -88,13 +88,14 @@ module FormatParser
|
|
88
88
|
# given to `.parse`. The accepted keyword arguments are the same as the ones for `parse`.
|
89
89
|
#
|
90
90
|
# @param url[String, URI] the HTTP(S) URL to request the object from using Faraday and `Range:` requests
|
91
|
+
# @param headers[Hash] (optional) the HTTP headers to request the object from using Faraday
|
91
92
|
# @param kwargs the keyword arguments to be delegated to `.parse`
|
92
93
|
# @see {.parse}
|
93
|
-
def self.parse_http(url, **kwargs)
|
94
|
+
def self.parse_http(url, headers: {}, **kwargs)
|
94
95
|
# Do not extract the filename, since the URL
|
95
96
|
# can really be "anything". But if the caller
|
96
97
|
# provides filename_hint it will be carried over
|
97
|
-
parse(RemoteIO.new(url), **kwargs)
|
98
|
+
parse(RemoteIO.new(url, headers: headers), **kwargs)
|
98
99
|
end
|
99
100
|
|
100
101
|
# Parses the file at the given `path` and returns the results as if it were any IO
|
data/lib/remote_io.rb
CHANGED
@@ -24,9 +24,11 @@ class FormatParser::RemoteIO
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# @param uri[URI, String] the remote URL to obtain
|
27
|
-
|
27
|
+
# @param headers[Hash] (optional) the HTTP headers to be used in the HTTP request
|
28
|
+
def initialize(uri, headers: {})
|
28
29
|
require 'faraday'
|
29
30
|
require 'faraday_middleware/response/follow_redirects'
|
31
|
+
@headers = headers
|
30
32
|
@uri = uri
|
31
33
|
@pos = 0
|
32
34
|
@remote_size = false
|
@@ -79,7 +81,7 @@ class FormatParser::RemoteIO
|
|
79
81
|
# We use a GET and not a HEAD request followed by a GET because
|
80
82
|
# S3 does not allow HEAD requests if you only presigned your URL for GETs, so we
|
81
83
|
# combine the first GET of a segment and retrieving the size of the resource
|
82
|
-
conn = Faraday.new do |faraday|
|
84
|
+
conn = Faraday.new(headers: @headers) do |faraday|
|
83
85
|
faraday.use FaradayMiddleware::FollowRedirects
|
84
86
|
# we still need the default adapter, more details: https://blog.thecodewhisperer.com/permalink/losing-time-to-faraday
|
85
87
|
faraday.adapter Faraday.default_adapter
|
@@ -102,6 +102,25 @@ describe 'Fetching data from HTTP remotes' do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
it 'sends provided HTTP headers in the request' do
|
106
|
+
# Faraday is required only after calling .parse_http
|
107
|
+
# This line is just to trigger this require, then it's possible to
|
108
|
+
# add an expectation of how Faraday is initialized after.
|
109
|
+
FormatParser.parse_http('invalid_url') rescue nil
|
110
|
+
|
111
|
+
expect(Faraday)
|
112
|
+
.to receive(:new)
|
113
|
+
.with(headers: {'test-header' => 'test-value'})
|
114
|
+
.and_call_original
|
115
|
+
|
116
|
+
file_information = FormatParser.parse_http(
|
117
|
+
'http://localhost:9399//TIFF/test.tif',
|
118
|
+
headers: {'test-header' => 'test-value'}
|
119
|
+
)
|
120
|
+
|
121
|
+
expect(file_information.format).to eq(:tif)
|
122
|
+
end
|
123
|
+
|
105
124
|
after(:all) do
|
106
125
|
@server.stop
|
107
126
|
@server_thread.join(0.5)
|
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.
|
4
|
+
version: 0.29.0
|
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-02-
|
12
|
+
date: 2021-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ks
|