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.
29 30 31 |
# File 'lib/nice/middleware.rb', line 29 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/nice/middleware.rb', line 33 def call(env) @doc = nil @referer = nil status, @headers, @body = @app.call(env) p "" p "!!!!!!!! RAILS RESPONSE HEADERS: #{@headers}" p "" @call_is_js = Rack::Request.new(env).xhr? @app_resp_is_js = js? if !@app_resp_is_js && (html? || @call_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 @call_is_js @headers = {"Content-Type" => "text/javascript"} end [status, @headers, self] else [status, @headers, @body] end end |
#each(&block) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nice/middleware.rb', line 64 def each(&block) if !@app_resp_is_js && (html? || @call_is_js) block.call("<!-- NICE Interception -->\n") block.call( Nice::Logic.run( @method, @path, @referer, doc, @call_is_js) ) else block.call(@body) end end |