Class: Rack::Fernet
- Inherits:
-
Object
- Object
- Rack::Fernet
- Defined in:
- lib/rack/fernet.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, secret, content_type = "application/json") ⇒ Fernet
constructor
A new instance of Fernet.
Constructor Details
#initialize(app, secret, content_type = "application/json") ⇒ Fernet
Returns a new instance of Fernet.
24 25 26 27 28 |
# File 'lib/rack/fernet.rb', line 24 def initialize(app, secret, content_type="application/json") @app = app @secret = secret @content_type = content_type end |
Instance Method Details
#call(env) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rack/fernet.rb', line 30 def call(env) payload = env["rack.input"].read verifier = ::Fernet.verifier(@secret, payload) if verifier.valid? env["CONTENT_TYPE"] = @content_type env["rack.input"] = StringIO.new(verifier.) @app.call(env) elsif payload.size.zero? @app.call(env) else bad_request end end |