polipus 0.3.4 → 0.3.5

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjkyMTAxZWU0ODJmMzI5OTcwZjI0ZTFlNzZjOTYxNzY1MGUxOTJjZQ==
4
+ NGY4NjA2MTVlYmY1ZGJlYzJhMGRmYjc3M2Y4MjFiMmFkZWQ0OGYwNg==
5
5
  data.tar.gz: !binary |-
6
- OTg4M2UzY2I2ODNkMWMxZDYwMzkxOGI5MmRhMWJkN2I0N2ViYTMyMg==
6
+ Njg1ZDVjYzI0YWNmMmJhYTVlZTMwOTBkYTc0MzU3MDI5MjI0ZDkxOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWE4ZjM0NDA1NWJiMGVkYzUyMTM5ZWJjN2I3YTU5YTI2NDIwNmI0ZTNkZTRl
10
- NTg0MzQyOTgxMGYzZjBlZGVkMmE2ODJkZTA0ZTg3NzY0MTJjZTljYWEwN2Fm
11
- YTc4MjI3NGViMmNlMjQzNWIxODVlMmNlNWJjNDFhMzE1MzQxMjk=
9
+ NTM3MjFhOWNjNWY4MTZmYjdiMGUwYzEwNGRhNjdkOGE2NDY1MjkzZTFmOTIw
10
+ MmExOGU0MGRjNWEwYjM0MTA2OTE5YmUzMDM2ZDUzOWExOTc1YWFmOWJhNzQ5
11
+ N2IyZTc4NzQyYTkzN2I5MjdhOTJmMmMwMzI0ZjA3MGZiYjY4N2I=
12
12
  data.tar.gz: !binary |-
13
- YjRlMmVjYzA4MDVlYzAxMmM0NGYwMWFiYWMwNmYxNDg3MmMyOTY4YzQzZDQ2
14
- OWZjNWUzYjJlMzk3MDg5NjE4ZmQxYTk5MWQ1Y2M0ZmQ5MjhkYjQxZjdkNzRk
15
- ZjZjNzkyMjJmM2M0MzNiNDNkOTQxOWYyMDc2MDdhZTJlNWE1Y2M=
13
+ ZWEwZWFjNjEwOTJiZGRkMjAyOTM2OTM0NzlhNjEwMjdlYjlmNDZiOWRiZmU5
14
+ ZDQ2YjJlYzJiZTM5NzM0ZWM0ZTQ4MDhhNWQ1YjgzZDRkYTFmNjgzMmU4YmMz
15
+ NzZiMWQ3MzdmOGE2ZjI2MDUzNzk2ODMzMmM4ODA1MWI5OGFhODQ=
data/lib/polipus.rb CHANGED
@@ -35,6 +35,10 @@ module Polipus
35
35
  proxy_host: nil,
36
36
  # proxy server port number
37
37
  proxy_port: false,
38
+ # proxy server username
39
+ proxy_user: nil,
40
+ # proxy server password
41
+ proxy_pass: nil,
38
42
  # HTTP read timeout in seconds
39
43
  read_timeout: 30,
40
44
  # HTTP open connection timeout in seconds
data/lib/polipus/http.rb CHANGED
@@ -95,13 +95,29 @@ module Polipus
95
95
  # The proxy port
96
96
  #
97
97
  def proxy_port
98
- return proxy_host_port.last unless @opts[:proxy_host_port].nil?
98
+ return proxy_host_port[1] unless @opts[:proxy_host_port].nil?
99
99
  @opts[:proxy_port].respond_to?(:call) ? @opts[:proxy_port].call(self) : @opts[:proxy_port]
100
100
  end
101
101
 
102
+ #
103
+ # The proxy username
104
+ #
105
+ def proxy_user
106
+ return proxy_host_port[2] unless @opts[:proxy_host_port].nil?
107
+ @opts[:proxy_user].respond_to?(:call) ? @opts[:proxy_user].call(self) : @opts[:proxy_user]
108
+ end
109
+
110
+ #
111
+ # The proxy password
112
+ #
113
+ def proxy_pass
114
+ return proxy_host_port[3] unless @opts[:proxy_host_port].nil?
115
+ @opts[:proxy_pass].respond_to?(:call) ? @opts[:proxy_pass].call(self) : @opts[:proxy_pass]
116
+ end
117
+
102
118
  #
103
119
  # Shorthand to get proxy info with a single call
104
- # It returns an array of ['addr', port]
120
+ # It returns an array of ['addr', port, 'user', 'pass']
105
121
  #
106
122
  def proxy_host_port
107
123
  @opts[:proxy_host_port].respond_to?(:call) ? @opts[:proxy_host_port].call(self) : @opts[:proxy_host_port]
@@ -175,6 +191,11 @@ module Polipus
175
191
  req = Net::HTTP::Get.new(full_path, opts)
176
192
  # HTTP Basic authentication
177
193
  req.basic_auth url.user, url.password if url.user
194
+ if @opts[:http_user]
195
+ req.basic_auth @opts[:http_user], @opts[:http_password]
196
+ end
197
+ # urls auth schema has higher priority
198
+ req.basic_auth url.user, url.password if url.user
178
199
  response = connection(url).request(req)
179
200
  finish = Time.now
180
201
  response_time = ((finish - start) * 1000).round
@@ -213,7 +234,7 @@ module Polipus
213
234
  @opts[:logger].debug { "Request #{url} using proxy: #{proxy_host}:#{proxy_port}" }
214
235
  end
215
236
 
216
- http = Net::HTTP.new(url.host, url.port, proxy_host, proxy_port)
237
+ http = Net::HTTP.new(url.host, url.port, proxy_host, proxy_port, proxy_user, proxy_pass)
217
238
 
218
239
  http.read_timeout = read_timeout if read_timeout
219
240
  http.open_timeout = open_timeout if open_timeout
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Polipus
3
- VERSION = '0.3.4'
3
+ VERSION = '0.3.5'
4
4
  HOMEPAGE = 'https://github.com/taganaka/polipus'
5
5
  end
data/spec/http_spec.rb CHANGED
@@ -45,10 +45,21 @@ describe Polipus::HTTP do
45
45
  http.proxy_host.should eq '127.0.0.0'
46
46
  end
47
47
 
48
+ it 'should set proxy w/ auth correctly using shorthand method' do
49
+ http = Polipus::HTTP.new(proxy_host_port: -> _con { ['127.0.0.0', 8080, 'a', 'b'] })
50
+ http.proxy_host_port.should eq ['127.0.0.0', 8080, 'a', 'b']
51
+ http.proxy_port.should be 8080
52
+ http.proxy_host.should eq '127.0.0.0'
53
+ http.proxy_user.should eq 'a'
54
+ http.proxy_pass.should eq 'b'
55
+ end
56
+
48
57
  it 'should set proxy settings' do
49
- http = Polipus::HTTP.new(proxy_host: '127.0.0.0', proxy_port: 8080)
58
+ http = Polipus::HTTP.new(proxy_host: '127.0.0.0', proxy_port: 8080, proxy_user: 'a', proxy_pass: 'b')
50
59
  http.proxy_port.should be 8080
51
60
  http.proxy_host.should eq '127.0.0.0'
61
+ http.proxy_user.should eq 'a'
62
+ http.proxy_pass.should eq 'b'
52
63
  end
53
64
 
54
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polipus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Laurita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-23 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-bloomfilter