Class: Net::HTTP::Paranoid
- Inherits:
-
Object
- Object
- Net::HTTP::Paranoid
- Defined in:
- lib/net/http/paranoid.rb
Defined Under Namespace
Classes: NotAllowedHostError, ParanoidError
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#blacklist ⇒ Object
Returns the value of attribute blacklist.
-
#whitelist ⇒ Object
Returns the value of attribute whitelist.
Instance Method Summary collapse
- #allow?(address) ⇒ Boolean
-
#initialize(opts = {}) ⇒ Paranoid
constructor
A new instance of Paranoid.
- #wrap(http) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Paranoid
Returns a new instance of Paranoid.
14 15 16 17 18 |
# File 'lib/net/http/paranoid.rb', line 14 def initialize(opts={}) opts = OpenStruct.new(opts) @blacklist = opts.blacklist || [] @whitelist = opts.whitelist || [] end |
Instance Attribute Details
#blacklist ⇒ Object
Returns the value of attribute blacklist.
11 12 13 |
# File 'lib/net/http/paranoid.rb', line 11 def blacklist @blacklist end |
#whitelist ⇒ Object
Returns the value of attribute whitelist.
12 13 14 |
# File 'lib/net/http/paranoid.rb', line 12 def whitelist @whitelist end |
Instance Method Details
#allow?(address) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/net/http/paranoid.rb', line 27 def allow?(address) name, _, _, ip = TCPSocket.gethostbyname(address) [ [@whitelist, true], [@blacklist, false] ].each do |list, ret| (list || []).each do |a| return ret if a === address return ret if a === name return ret if a === ip end end !lan?(address) end |
#wrap(http) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/net/http/paranoid.rb', line 20 def wrap(http) unless allow?(http.address) raise NotAllowedHostError, "#{http.address} is not allowed host" end http end |