Class: RemoteImageFetch::UriRestrictions
- Inherits:
-
Object
- Object
- RemoteImageFetch::UriRestrictions
- Defined in:
- lib/remote_image_fetch/uri_restrictions.rb
Overview
Wrap cURL response as if it’s an error
Instance Method Summary collapse
- #check(url) ⇒ Object
-
#initialize(options = {}) ⇒ UriRestrictions
constructor
A new instance of UriRestrictions.
Constructor Details
#initialize(options = {}) ⇒ UriRestrictions
Returns a new instance of UriRestrictions.
7 8 9 10 11 12 13 |
# File 'lib/remote_image_fetch/uri_restrictions.rb', line 7 def initialize( = {}) @schemes = [:schemes] || ['http', 'https'] @ports = [:ports] || [80, 443, 8080] @ip_blacklist = [:ip_blacklist] @host_blacklist = [:host_blacklist] end |
Instance Method Details
#check(url) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/remote_image_fetch/uri_restrictions.rb', line 15 def check(url) uri = URI.parse(url) check_scheme! uri check_port! uri check_host! uri Resolv.each_address(uri.hostname) do |addr| raise "IP blacklisted - #{addr} for #{url}" if ip_blacklist_matches?(addr) end end |