allow viewing request headers (#8)

* allow viewing request headers

* text/plain output for headers
This commit is contained in:
Aleksandar Kostadinov 2017-09-14 03:52:14 +08:00 committed by Ben Parees
parent 1f3d5b79af
commit 5ce019b742

View file

@ -11,6 +11,19 @@ map '/lobster' do
run Rack::Lobster.new run Rack::Lobster.new
end end
map '/headers' do
headers = proc do |env|
[200, { "Content-Type" => "text/plain" }, [
env.select {|key,val| key.start_with? 'HTTP_'}
.collect {|key, val| [key.sub(/^HTTP_/, ''), val]}
.collect {|key, val| "#{key}: #{val}"}
.sort
.join("\n")
]]
end
run headers
end
map '/' do map '/' do
welcome = proc do |env| welcome = proc do |env|
[200, { "Content-Type" => "text/html" }, [<<WELCOME_CONTENTS [200, { "Content-Type" => "text/html" }, [<<WELCOME_CONTENTS