Class: ConnectorsShared::Middleware::RestrictHostnames
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- ConnectorsShared::Middleware::RestrictHostnames
- Defined in:
- lib/connectors_shared/middleware/restrict_hostnames.rb
Defined Under Namespace
Classes: AddressNotAllowed
Constant Summary collapse
- URL_PATTERN =
/\Ahttp/
Instance Attribute Summary collapse
-
#allowed_hosts ⇒ Object
readonly
Returns the value of attribute allowed_hosts.
-
#allowed_ips ⇒ Object
readonly
Returns the value of attribute allowed_ips.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app = nil, options = {}) ⇒ RestrictHostnames
constructor
A new instance of RestrictHostnames.
Constructor Details
#initialize(app = nil, options = {}) ⇒ RestrictHostnames
Returns a new instance of RestrictHostnames.
23 24 25 26 27 |
# File 'lib/connectors_shared/middleware/restrict_hostnames.rb', line 23 def initialize(app = nil, = {}) super(app) @allowed_hosts = [:allowed_hosts] @allowed_ips = ips_from_hosts(@allowed_hosts) end |
Instance Attribute Details
#allowed_hosts ⇒ Object (readonly)
Returns the value of attribute allowed_hosts.
21 22 23 |
# File 'lib/connectors_shared/middleware/restrict_hostnames.rb', line 21 def allowed_hosts @allowed_hosts end |
#allowed_ips ⇒ Object (readonly)
Returns the value of attribute allowed_ips.
21 22 23 |
# File 'lib/connectors_shared/middleware/restrict_hostnames.rb', line 21 def allowed_ips @allowed_ips end |
Instance Method Details
#call(env) ⇒ Object
29 30 31 32 |
# File 'lib/connectors_shared/middleware/restrict_hostnames.rb', line 29 def call(env) raise AddressNotAllowed.new("Address not allowed for #{env[:url]}") if denied?(env) @app.call(env) end |