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
1 changed files with 13 additions and 0 deletions

View File

@ -11,6 +11,19 @@ map '/lobster' do
run Rack::Lobster.new
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
welcome = proc do |env|
[200, { "Content-Type" => "text/html" }, [<<WELCOME_CONTENTS