Class: Rack::Unbasic
- Inherits:
-
Object
- Object
- Rack::Unbasic
- Defined in:
- lib/rack/unbasic.rb
Instance Method Summary collapse
-
#bad_request(location) ⇒ Object
Set the redirect URL for 400 responses from the downstream app.
- #call(env) ⇒ Object
-
#initialize(app, &block) ⇒ Unbasic
constructor
Create the middleware.
-
#unauthorized(location) ⇒ Object
Set the redirect URL for 401 responses from the downstream app.
Constructor Details
#initialize(app, &block) ⇒ Unbasic
Create the middleware. You can pass a block to configure how to handle 401 and 400 responses from the downstream app. See #unauthorized and #bad_request.
8 9 10 11 12 |
# File 'lib/rack/unbasic.rb', line 8 def initialize(app, &block) # :yields: self @app = app @locations = {} block.call(self) if block end |
Instance Method Details
#bad_request(location) ⇒ Object
Set the redirect URL for 400 responses from the downstream app.
20 21 22 |
# File 'lib/rack/unbasic.rb', line 20 def bad_request(location) @locations["bad_request"] = location end |
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rack/unbasic.rb', line 24 def call(env) @env = env clean_session_data || @response = @app.call(@env) case status_code when 401 when 400 bad_request_response else store_credentials @response end end |
#unauthorized(location) ⇒ Object
Set the redirect URL for 401 responses from the downstream app.
15 16 17 |
# File 'lib/rack/unbasic.rb', line 15 def (location) @locations["unauthorized"] = location end |