Barebone Web Development With Rack

Tagged rack, ruby, dump, headers  Languages ruby

Create a file named config.ru:

run lambda { |env|
  [200, {"Content-Type" => "text/html"}, [view(env)]]
}

def view(env)
  res = ""
  res << "<html><body><pre>"
  env.sort.each do |key, value|
    res << "#{key}: #{value}"
    res << "\n"
  end
  res << "</pre></body></html>"
  res
end

Start the server with e.g. rackup, puma, or thin:

$ rackup

Access http://localhost:9292 to see the request headers.