Skip to content

Instantly share code, notes, and snippets.

@tb0yd
Created November 3, 2010 14:13
Show Gist options
  • Save tb0yd/661119 to your computer and use it in GitHub Desktop.
Save tb0yd/661119 to your computer and use it in GitHub Desktop.
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