Class: FunApi::Middleware::TrustedHost
- Inherits:
-
Object
- Object
- FunApi::Middleware::TrustedHost
- Defined in:
- lib/funapi/middleware/trusted_host.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, **options) ⇒ TrustedHost
constructor
A new instance of TrustedHost.
Constructor Details
#initialize(app, **options) ⇒ TrustedHost
Returns a new instance of TrustedHost.
4 5 6 7 |
# File 'lib/funapi/middleware/trusted_host.rb', line 4 def initialize(app, **) @app = app @allowed_hosts = Array([:allowed_hosts] || []) end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/funapi/middleware/trusted_host.rb', line 9 def call(env) host = env["HTTP_HOST"]&.split(":")&.first unless host_allowed?(host) return [ 400, {"content-type" => "application/json"}, [JSON.dump(detail: "Invalid host header")] ] end @app.call(env) end |