[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Most succinct way to parse an HTTP header string
- From: Kevin Martin <kev82@...>
- Date: Thu, 29 Aug 2013 15:28:50 +0100
On 29 Aug 2013, at 15:13, David Crayford wrote:
> want to parse a HTTP header string "name:value" pair.
I've been using the following code to parse the headers out of an Rackspace API response for 18 months now. self._response is a string containing the whole http response.
local headerString = self._response:match("[%g ]+\r\n([%g \r\n]+)\r\n\r\n") .. "\r\n"
if headerString == nil then error("Couldn't find header") end
for k, v in headerString:gmatch("([%a%d%-]+): ([%g ]+)\r\n") do
if k == nil then error("Unparseable Header") end
headers[k] = v
end
return headers
Thanks,
Kevin