Skip to content

Commit

Permalink
allow viewing request headers (sclorg#8)
Browse files Browse the repository at this point in the history
* allow viewing request headers

* text/plain output for headers
  • Loading branch information
akostadinov authored and bparees committed Sep 13, 2017
1 parent 1f3d5b7 commit 5ce019b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ce019b

Please sign in to comment.