http-proxy 0.3.0 → 0.3.1

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: eaeb307b91714f53a84e1b24e5a0160e345f1d7e37dd5b232962b7a5d42d50a2
4
- data.tar.gz: 26e0aff91af5bbb357bf92d82c2f259c26fbd380ce927be303bb46d5bfb75b47
3
+ metadata.gz: a8e6a800ddd9b75f3983dfb76b172e71971f82af1d0e38f3de15bdb1f15203df
4
+ data.tar.gz: e99c31054ab5314d7bd1955eca31b93adb5b51d7f5716889467e83ea6b08a4a6
5
5
  SHA512:
6
- metadata.gz: c7e954eaa1f88f26bc1247771ad6f8cc02160f09d284ca7515956dc81391e81495165f64405ad2892de43f69a4affd010b048c808c8578d1d07bbeebb328f12d
7
- data.tar.gz: f53b8d3430ce567b57ddce1a9466a85be309ec190731d24bf3c8db420821b3e0f4549d16d5856f27cb1e3b0b4db2bc16504933c6960c4edd5c9b5868c8b6420b
6
+ metadata.gz: 9b0aa3f9f64d5cad46d3b36fab27c9626ce26d9155d8ed00b540bba77ee72b6c5d00a2551b9919ee641135706f03bbe9595b540cc87aecdb628e51ab38efcb76
7
+ data.tar.gz: 0f264cc280c58a0cf4447eb3af7682b63a1f13ddd767952e4deb387ee4ec1a2a8a1f7c511a24abb223b37df520a1ba4db7fee8218906ddc7191e4246fe33c098
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- http-proxy (0.3.0)
4
+ http-proxy (0.3.1)
5
5
  http (~> 4.4, >= 4.4.1)
6
- proxy_pool (~> 0.2.2)
6
+ proxy_pool (~> 0.3.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -27,7 +27,7 @@ GEM
27
27
  http-parser (1.2.1)
28
28
  ffi-compiler (>= 1.0, < 2.0)
29
29
  minitest (5.11.3)
30
- proxy_pool (0.2.2)
30
+ proxy_pool (0.3.0)
31
31
  http (~> 4.4, >= 4.4.1)
32
32
  public_suffix (4.0.5)
33
33
  rake (13.0.1)
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
1
  # HTTP::Proxy
2
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fzt2%2Fhttp-proxy.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fzt2%2Fhttp-proxy?ref=badge_shield)
3
-
4
2
 
5
3
  HTTP::Proxy allows you sending HTTP request via proxy automatically. This library extends gem HTTP by patching HTTP::Chainable to make proxy http request possible.
6
4
 
@@ -49,7 +47,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
49
47
 
50
48
  ## Contributing
51
49
 
52
- Bug reports and pull requests are welcome on GitHub at https://github.com/zt2/http-proxy.
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hi_ztz/http-proxy.
53
51
 
54
52
  ## License
55
53
 
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'http-proxy'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'http-proxy'
6
- spec.version = '0.3.0'
6
+ spec.version = '0.3.1'
7
7
  spec.authors = ['hi_ztz']
8
8
  spec.email = ['hi_ztz@protonmail.com']
9
9
 
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rake', '~> 13.0'
27
27
  spec.add_development_dependency 'minitest', '~> 5.0'
28
28
 
29
- spec.add_runtime_dependency 'proxy_pool', '~> 0.2.2'
29
+ spec.add_runtime_dependency 'proxy_pool', '~> 0.3.0'
30
30
  spec.add_runtime_dependency 'http', '~> 4.4', '>= 4.4.1'
31
31
  end
@@ -5,17 +5,32 @@ module HTTP
5
5
  module Chainable
6
6
  # Choose a proxy to send HTTP request
7
7
  #
8
- # @param anonymous [Boolean] Using anonymous proxy or not
9
- def proxy(anonymous = true, &block)
10
- if anonymous
11
- p = ProxyPool.get_high_anonymous_proxy
12
- elsif block_given?
13
- p = ProxyPool.get(&block)
14
- else
15
- p = ProxyPool.get
8
+ # @param lazy_mode [Boolean] Re-use the last working proxy
9
+ def proxy(lazy_mode: true, &block)
10
+ p = if lazy_mode && !@_last_proxy.nil?
11
+ @_last_proxy
12
+ else
13
+ block_given? ? ProxyPool.get(&block) : ProxyPool.get
14
+ end
15
+
16
+ begin
17
+ ret = via(p['host'], p['port'])
18
+ @_last_proxy = p
19
+ rescue HTTP::ConnectionError, HTTP::TimeoutError => e
20
+ # Remove it from pool
21
+ ProxyPool.remove(p)
22
+
23
+ # Select another one
24
+ p = block_given? ? ProxyPool.get(&block) : ProxyPool.get
25
+ while p.nil?
26
+ ProxyPool.update
27
+ p = block_given? ? ProxyPool.get(&block) : ProxyPool.get
28
+ end
29
+
30
+ retry
16
31
  end
17
32
 
18
- via(p['host'], p['port'])
33
+ ret
19
34
  end
20
35
  end
21
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hi_ztz
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.2
61
+ version: 0.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.2
68
+ version: 0.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: http
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,7 @@ files:
100
100
  - LICENSE.txt
101
101
  - README.md
102
102
  - Rakefile
103
+ - bin/console
103
104
  - http-proxy.gemspec
104
105
  - lib/http-proxy.rb
105
106
  - lib/http-proxy/chainable.rb