Skip to content

Instantly share code, notes, and snippets.

@mikehale
Created December 16, 2008 14:01
Show Gist options
  • Save mikehale/36462 to your computer and use it in GitHub Desktop.
Save mikehale/36462 to your computer and use it in GitHub Desktop.
def parse_headers
request = "GET /remote/path/img.gif HTTP/1.1\r\nAccept-Language: en-us,en;q=0.5\r\nCache-Control: max-age=0\r\nIf-None-Match: \"58dc30c-216-3d878fe2\"-gzip\r\nX-Forwarded-For: 127.0.0.1\r\nAccept: image/png,image/*;q=0.8,*/*;q=0.5\r\nConnection: Keep-Alive\r\nX-Forwarded-Server: www.example.com\r\nAccept-Encoding: gzip,deflate\r\nUser-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4\r\nCookie: cookie1=YWJj; cookie2=ZGVm\r\nReferer: http://www.example.com/posts/\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nHost: localhost:4001\r\nX-Forwarded-Host: www.example.com\r\nIf-Modified-Since: Tue, 17 Sep 2002 20:26:10 GMT\r\n\r\n"
tmp = {}
request.split("\r\n")[1..-1].each{|e|
k,v = e.split(': ')
tmp[k]=v
}
tmp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment