down 4.6.1 → 4.7.0

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: 2b7f648a8ac6e6d684978399684d40d346f64b60b09cd65cefd5c51a079ff232
4
- data.tar.gz: 867598c75cbdfb7ad946104c01ea9d97c753953b2575e5ccb6355dabbc625ff7
3
+ metadata.gz: 2a731d7a9096d275efb334bb06f6a7d2060f9711ac8973f4db286170a0f288e9
4
+ data.tar.gz: 89924b87d6fea6ba6fb3d5fc2ceed6d50a312758a1a9ec57baaeeaefd5283a8f
5
5
  SHA512:
6
- metadata.gz: add25eccfc67ddd7070ea8f7c6315566399c91de00c90389ac00b14b882d17220ed8b064a6036e77d142e23fef5339307ccbf9266a0cbd727a8b7de63d412301
7
- data.tar.gz: fa3de4d91657ec8cfaa1cda9e25ed61cebfd8ab9ea198dbf9ef2576a73d4dff30aa9d8f2b355718d607561b97976634fc9086fd782b97211c447f0088e549be1
6
+ metadata.gz: f63e9bbf2f5e8f10105816ffc9369f5aff75e65667ffb85e0e0c71f96c0b1861c5e727d379c55fd5695855e409ca49c306ce70fa5927a7bbb826cfb780b2ac77
7
+ data.tar.gz: 49db0e8cee2494962384613c4cbb84b232e3e9a6872cc13a19e7a4b4f86b86e09e70a65620ab1c067a8557f0ae43de9d37f2fc0255d8fed42e46ed4705aa7911
@@ -1,3 +1,7 @@
1
+ ## 4.7.0 (2018-11-18)
2
+
3
+ * Allow request headers to be passed via `:headers` to `Down::NetHttp#download` and `#open` (@janko-m)
4
+
1
5
  ## 4.6.1 (2018-10-24)
2
6
 
3
7
  * Release HTTP.rb version constraint to allow HTTP.rb 4.x (@janko-m)
data/README.md CHANGED
@@ -261,10 +261,10 @@ as open-uri doesn't support downloading on-demand.
261
261
 
262
262
  #### Redirects
263
263
 
264
- `Down.download` turns off open-uri's following redirects, as open-uri doesn't
265
- have a way to limit the maximum number of hops, and implements its own. By
266
- default maximum of 2 redirects will be followed, but you can change it via the
267
- `:max_redirects` option:
264
+ `Down::NetHttp#download` turns off open-uri's following redirects, as open-uri
265
+ doesn't have a way to limit the maximum number of hops, and implements its own.
266
+ By default maximum of 2 redirects will be followed, but you can change it via
267
+ the `:max_redirects` option:
268
268
 
269
269
  ```rb
270
270
  Down::NetHttp.download("http://example.com/image.jpg") # 2 redirects allowed
@@ -278,24 +278,42 @@ Down::NetHttp.open("http://example.com/image.jpg", max_redirects: 0) # 0 red
278
278
 
279
279
  #### Proxy
280
280
 
281
- Both `Down.download` and `Down.open` support a `:proxy` option, where you can
282
- specify a URL to an HTTP proxy which should be used when downloading.
281
+ An HTTP proxy can be specified via the `:proxy` option:
283
282
 
284
283
  ```rb
285
284
  Down::NetHttp.download("http://example.com/image.jpg", proxy: "http://proxy.org")
286
- Down::NetHttp.open("http://example.com/image.jpg", proxy: "http://user:password@proxy.org")
285
+ Down::NetHttp.open("http://example.com/image.jpg", proxy: "http://user:password@proxy.org")
287
286
  ```
288
287
 
289
288
  #### Timeouts
290
289
 
291
- Both `Down.download` and `Down.open` support `:read_timeout` and `:open_timeout`
292
- options, which are forwarded to `Net::HTTP`:
290
+ Timeouts can be configured via the `:open_timeout` and `:read_timeout` options:
293
291
 
294
292
  ```rb
295
293
  Down::NetHttp.download("http://example.com/image.jpg", open_timeout: 5)
296
294
  Down::NetHttp.open("http://example.com/image.jpg", read_timeout: 10)
297
295
  ```
298
296
 
297
+ #### Headers
298
+
299
+ Request headers can be added via the `:headers` option:
300
+
301
+ ```rb
302
+ Down::NetHttp.download("http://example.com/image.jpg", headers: { "Header" => "Value" })
303
+ Down::NetHttp.open("http://example.com/image.jpg", headers: { "Header" => "Value" })
304
+ ```
305
+
306
+ #### SSL options
307
+
308
+ The `:ssl_ca_cert` and `:ssl_verify_mode` options are supported, and they have
309
+ the same semantics as in `open-uri`:
310
+
311
+ ```rb
312
+ Down::NetHttp.open("http://example.com/image.jpg",
313
+ ssl_ca_cert: "/path/to/cert",
314
+ ssl_verify_mode: OpenSSL::SSL::VERIFY_PEER)
315
+ ```
316
+
299
317
  #### Additional options
300
318
 
301
319
  Any additional options passed to `Down.download` will be forwarded to
@@ -307,14 +325,6 @@ Down::NetHttp.download "http://example.com/image.jpg",
307
325
  read_timeout: 5
308
326
  ```
309
327
 
310
- `Down.open` accepts `:ssl_verify_mode` and `:ssl_ca_cert` options with the same
311
- semantics as in open-uri, and any options with String keys will be interpreted
312
- as request headers, like with open-uri.
313
-
314
- ```rb
315
- Down::NetHttp.open("http://example.com/image.jpg", {"Authorization" => "..."})
316
- ```
317
-
318
328
  You can also initialize the backend with default options:
319
329
 
320
330
  ```rb
@@ -32,6 +32,7 @@ module Down
32
32
  progress_proc = options.delete(:progress_proc)
33
33
  content_length_proc = options.delete(:content_length_proc)
34
34
  destination = options.delete(:destination)
35
+ headers = options.delete(:headers) || {}
35
36
 
36
37
  # Use open-uri's :content_lenth_proc or :progress_proc to raise an
37
38
  # exception early if the file is too large.
@@ -71,6 +72,7 @@ module Down
71
72
  end
72
73
 
73
74
  open_uri_options.merge!(options)
75
+ open_uri_options.merge!(headers)
74
76
 
75
77
  uri = ensure_uri(addressable_normalize(url))
76
78
 
@@ -249,10 +251,11 @@ module Down
249
251
  http.read_timeout = options[:read_timeout] if options.key?(:read_timeout)
250
252
  http.open_timeout = options[:open_timeout] if options.key?(:open_timeout)
251
253
 
252
- request_headers = options.select { |key, value| key.is_a?(String) }
253
- request_headers["Accept-Encoding"] = "" # Net::HTTP's inflater causes FiberErrors
254
+ headers = options.select { |key, value| key.is_a?(String) }
255
+ headers.merge!(options[:headers]) if options[:headers]
256
+ headers["Accept-Encoding"] = "" # Net::HTTP's inflater causes FiberErrors
254
257
 
255
- get = Net::HTTP::Get.new(uri.request_uri, request_headers)
258
+ get = Net::HTTP::Get.new(uri.request_uri, headers)
256
259
  get.basic_auth(uri.user, uri.password) if uri.user || uri.password
257
260
 
258
261
  [http, get]
@@ -1,5 +1,5 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  module Down
4
- VERSION = "4.6.1"
4
+ VERSION = "4.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: down
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.1
4
+ version: 4.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable