lib/rack-xslview.rb in rack-xslview-0.2.0 vs lib/rack-xslview.rb in rack-xslview-0.2.1

- old
+ new

@@ -17,17 +17,22 @@ @xslt = @options[:myxsl] end end def call(env) + # No matter what, @app will be called - status, headers, body = @app.call(env) + status, headers, body = original_response = @app.call(env) + return original_response if (status == 304 || status == 204) + + return original_response unless headers["Content-Type"].to_s.match(/(ht|x)ml/) + # If setup includes paths to exclude from xslt processing, check them checknoxsl(env) if @options[:noxsl] - # Obtain entire request body, check to make sure it can be processed + # Obtain entire request body, ensuring sure it can be processed myxml = getResponse(body) # Should XSL file be reloaded? if @options[:reload] == true @xslt = XML::XSLT.new() @@ -54,12 +59,12 @@ headers.delete('Content-Length') headers['Content-Length'] = newbody[0].length.to_s [status, headers, newbody] rescue XSLViewError - # TODO Logging: "Rack XSLView not processed" if env['RACK_ENV'] == 'development' - [status, headers, body] + # TODO Log: "Rack XSLView not processed" if env['RACK_ENV'] == 'development' + original_response end private def checknoxsl(env) @options[:noxsl].each { |path| @@ -76,11 +81,11 @@ } return newbody end def checkForXml(x) # Abort processing if content cannot be processed by libxslt - raise XSLViewError unless x[0,1] == '<' + raise XSLViewError unless x[0] == '<' if @options[:excludehtml] == true raise XSLViewError if x.include? '<html' end end @@ -93,6 +98,5 @@ } return false end end end -