Class: Nice::Middleware
- Inherits:
-
Object
- Object
- Nice::Middleware
- Defined in:
- lib/nice/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
24 25 26 |
# File 'lib/nice/middleware.rb', line 24 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nice/middleware.rb', line 28 def call(env) @doc = nil @referer = nil status, @headers, @body = @app.call(env) @is_js = Rack::Request.new(env).xhr? if html? || @is_js @referer = env["HTTP_REFERER"] @method = env["REQUEST_METHOD"] @path = env["PATH_INFO"] # in case 2+3 the response will be plain javascript if @is_js @headers = {"Content-Type" => "text/javascript"} end [status, @headers, self] else [status, @headers, @body] end end |