Skip to content

Instantly share code, notes, and snippets.

@ntalbott
Forked from mikehale/gist:36462
Created December 16, 2008 22:11
Show Gist options
  • Save ntalbott/36841 to your computer and use it in GitHub Desktop.
Save ntalbott/36841 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"
request.split("\r\n")[1..-1].inject({}) do |h,e|
k,v = e.split(': ') # Concern - could this ever split in to 3 or more elements?
h[k] = v
h
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment