down 4.6.1 → 4.7.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +27 -17
- data/lib/down/net_http.rb +6 -3
- data/lib/down/version.rb +1 -1
- 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: 2a731d7a9096d275efb334bb06f6a7d2060f9711ac8973f4db286170a0f288e9
|
|
4
|
+
data.tar.gz: 89924b87d6fea6ba6fb3d5fc2ceed6d50a312758a1a9ec57baaeeaefd5283a8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f63e9bbf2f5e8f10105816ffc9369f5aff75e65667ffb85e0e0c71f96c0b1861c5e727d379c55fd5695855e409ca49c306ce70fa5927a7bbb826cfb780b2ac77
|
|
7
|
+
data.tar.gz: 49db0e8cee2494962384613c4cbb84b232e3e9a6872cc13a19e7a4b4f86b86e09e70a65620ab1c067a8557f0ae43de9d37f2fc0255d8fed42e46ed4705aa7911
|
data/CHANGELOG.md
CHANGED
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
|
|
265
|
-
have a way to limit the maximum number of hops, and implements its own.
|
|
266
|
-
default maximum of 2 redirects will be followed, but you can change it via
|
|
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
|
-
|
|
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",
|
|
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
|
-
|
|
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
|
data/lib/down/net_http.rb
CHANGED
|
@@ -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
|
-
|
|
253
|
-
|
|
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,
|
|
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]
|
data/lib/down/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2018-11-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: addressable
|