require "rack" def pp(hash) hash["HTTP_ACCEPT"].include?("text/html") ? pp_html(hash) : pp_plain(hash) end def pp_plain(hash) hash.map {|key,value| "#{key}: #{value}"}.sort.join("\n") end def pp_html(hash) hash.map {|key,value| CGI::escapeHTML("#{key}: #{value}")}.sort.join("
") end def headers(hash) headers = {} headers['Content-Type'] = 'text/html' if hash["HTTP_ACCEPT"].include?("text/html") headers end Rack::Handler::WEBrick.run lambda {|env| [200,headers(env),[pp(env)]]} , :Port=>3000 # credits to: https://stackoverflow.com/a/17396721/520567