module Rack class ChromeFrame def initialize(app, options={}) @app = app @options = options end def call(env) if env['HTTP_USER_AGENT'] =~ /MSIE/ if env['HTTP_USER_AGENT'] =~ /chromeframe/ status, headers, response = new_body = insert_tag(build_response_body(response)) new_headers = recalculate_body_length(headers, new_body) return [status, new_headers, new_body] elsif @options[:minimum].nil? or ie_version(env['HTTP_USER_AGENT']) < @options[:minimum] html = <<-HTML You need to use a real browser in order to use Diaspora!
HTML return [200, {'Content-Type' => 'text/html', 'Content-Length' => html.size.to_s},[html])] end end end def build_response_body(response) response_body = "" response.each { |part| response_body += part } response_body end def recalculate_body_length(headers, body) new_headers = headers new_headers["Content-Length"] = body.length.to_s new_headers end def insert_tag(body) head = <<-HEAD HEAD body.gsub!('', "\n" + head ) body end def ie_version(ua_string) ua_string.match(/MSIE (\S+)/)[1].to_f end end end