format_parser 0.28.0 → 0.29.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2212d92c3c0ca7aab0e60c9aa6559d0508ec2b8b39e4b2067990d97a7d78327
4
- data.tar.gz: 27736f9d52ea1e73a147d96d38608e268040648e61d2b913ca38f164f2d2d0b6
3
+ metadata.gz: b8efef8742cfefdcde0aa05ab32c726004325c2210b19e25ca2cf866ad786074
4
+ data.tar.gz: bbd59f6f046a35cff93ea4e20a5168c2912007b06b3fabe7a5b23f7a0ed70c34
5
5
  SHA512:
6
- metadata.gz: 5f63f74444df32d016fc25dc5c3731671690185b7ecf80ffc06da350b37d82b566f451508091245fec255c816121a115286dd04fb626aa4c1b694836fd645d97
7
- data.tar.gz: ee1917287bb7c50bd71d9a7756321e30fbc73aa5e3a4f42e4844eb9494dfe77e89a9a26622732772c9b29c4ea673f3401324d2e6bf67e5bdaa5dac991d12f821
6
+ metadata.gz: b4a7d965be6ff0cb0abf8cdec5f4d31259aada155ae465c1b31d5eba718f9d0071ee8b7a6b2061e6024add45d32b901c0f95a37373727a59fd4a6562041f52e9
7
+ data.tar.gz: d314cb6876185ddedcef01c67205cf0635c2d8aebd0871dfd7834f0f54c15c38c31db7cc730c6aea8f8a72aff85949fa6937d970dfb320120a5b8c843f003753
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.29.0
2
+ * Add option `headers:` to `FormatParser.parse_http`
3
+
1
4
  ## 0.28.0
2
5
  * Change `FormatParser.parse_http` to follow HTTP redirects
3
6
 
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
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '0.28.0'
2
+ VERSION = '0.29.0'
3
3
  end
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
- def initialize(uri)
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.28.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-17 00:00:00.000000000 Z
12
+ date: 2021-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ks