Created
March 28, 2018 16:26
-
-
Save swarley/2b38ab967823ed7351bc0ed1c8e82bd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RestClient | |
module Utils | |
def self.cgi_parse_header(line) | |
parts = _cgi_parseparam(';' + line).to_a | |
key = parts[0] | |
pdict = {} | |
while (p = parts.shift) | |
i = p.index('=') | |
if i | |
name = p[0...i].strip.downcase | |
value = p[i+1..-1].strip | |
if value.length >= 2 && value[0] == '"' && value[-1] == '"' | |
value = value[1...-1] | |
value = value.gsub('\\\\', '\\').gsub('\\"', '"') | |
end | |
pdict[name] = value | |
end | |
end | |
[key, pdict] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment