http-proxy 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +1 -3
- data/bin/console +15 -0
- data/http-proxy.gemspec +2 -2
- data/lib/http-proxy/chainable.rb +24 -9
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8e6a800ddd9b75f3983dfb76b172e71971f82af1d0e38f3de15bdb1f15203df
|
4
|
+
data.tar.gz: e99c31054ab5314d7bd1955eca31b93adb5b51d7f5716889467e83ea6b08a4a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b0aa3f9f64d5cad46d3b36fab27c9626ce26d9155d8ed00b540bba77ee72b6c5d00a2551b9919ee641135706f03bbe9595b540cc87aecdb628e51ab38efcb76
|
7
|
+
data.tar.gz: 0f264cc280c58a0cf4447eb3af7682b63a1f13ddd767952e4deb387ee4ec1a2a8a1f7c511a24abb223b37df520a1ba4db7fee8218906ddc7191e4246fe33c098
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
http-proxy (0.3.
|
4
|
+
http-proxy (0.3.1)
|
5
5
|
http (~> 4.4, >= 4.4.1)
|
6
|
-
proxy_pool (~> 0.
|
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.
|
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/
|
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
|
|
data/bin/console
ADDED
@@ -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__)
|
data/http-proxy.gemspec
CHANGED
@@ -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.
|
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.
|
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
|
data/lib/http-proxy/chainable.rb
CHANGED
@@ -5,17 +5,32 @@ module HTTP
|
|
5
5
|
module Chainable
|
6
6
|
# Choose a proxy to send HTTP request
|
7
7
|
#
|
8
|
-
# @param
|
9
|
-
def proxy(
|
10
|
-
if
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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.
|
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.
|
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.
|
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
|