Skip to content

Instantly share code, notes, and snippets.

@rking

rking/foo.rb Secret

Created September 3, 2012 19:49
Show Gist options
  • Save rking/0ca01f148efe7207bd60 to your computer and use it in GitHub Desktop.
Save rking/0ca01f148efe7207bd60 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
env = {
"HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"HTTP_ACCEPT_ENCODING"=>"gzip, deflate",
"HTTP_ACCEPT_LANGUAGE"=>"en-us",
"HTTP_CONNECTION"=>"keep-alive",
"HTTP_HOST"=>"localhost:9292",
"HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25",
"HTTP_VERSION"=>"HTTP/1.1",
'deleteme'=>1,
}
expected_env = {
"accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"accept_encoding"=>"gzip, deflate",
"accept_language"=>"en-us",
#???# "cache_control"=>"max-age=0",
"connection"=>"keep-alive",
"host"=>"localhost:9292",
"user_agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25",
"version"=>"HTTP/1.1"
}
def clean_headers env
Hash[env.map { |k,v| k[/^HTTP_(.+)/] ? [ $1.downcase , v ] : nil }.compact ]
end
require 'yaml'
puts expected_env.to_yaml, clean_headers(env).to_yaml
puts expected_env == clean_headers(env)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment