require "rack/hatena_star/version" module Rack class HatenaStar def initialize(app, options) @app, @options = app, options end def call(env) status, headers, body = @app.call(env) return [status, headers, body] unless html?(headers) res = Rack::Response.new([], status, headers) body.each do |b| res.write(b.sub('', <<-EOS)) EOS end body.close if body.respond_to? :close res.finish end private def html?(headers) headers['Content-Type'] =~ /text\/html/ end end end