Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@amiel
Forked from ddollar/gist:174320
Created August 24, 2009 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiel/174323 to your computer and use it in GitHub Desktop.
Save amiel/174323 to your computer and use it in GitHub Desktop.
require 'httparty'
require 'rack'
class Rack::Validate
attr_reader :app, :options
def initialize(app, options={})
@app = app
@options = options
end
def call(env)
code, headers, body = app.call(env)
headers['X-W3-Valid'] = invalid_markup?(body) ? 'false' : 'true'
ensure
return code, headers, body
end
private ######################################################################
def invalid_markup?(html)
query = { :fragment => html, :output => 'soap12' }
result = HTTParty.post('http://validator.w3.org/check', :body => query)
result.to_s.index('<m:validity>true</m:validity>').nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment