Created
November 3, 2010 14:13
-
-
Save tb0yd/661119 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JavascriptEraser | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
status, headers, response = @app.call(env) | |
if headers['Content-Type'] and headers['Content-Type'].include?("javascript") | |
response = "" | |
elsif response.respond_to?(:body) and response.body.is_a?(String) | |
response.body = response.body.gsub(/<script(.|\n)*?type(.|\n)*?javascript(.|\n)*?\/script>/,"") | |
elsif response.class.to_s != "Rack::File" | |
puts "JavascriptEraser: unknown response type: #{response.class}. check order of appearance in middleware stack." | |
end | |
[status, headers, response] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment