Skip to content

Instantly share code, notes, and snippets.

@swarley
Created March 28, 2018 16:26
Show Gist options
  • Save swarley/2b38ab967823ed7351bc0ed1c8e82bd9 to your computer and use it in GitHub Desktop.
Save swarley/2b38ab967823ed7351bc0ed1c8e82bd9 to your computer and use it in GitHub Desktop.
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