lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 29/08/2013 10:28 PM, Kevin Martin wrote:
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


Thanks kev, that's powerful stuff but what I'm looking for is a way to coerce REXX programmers to swap to Lua. The REXX parse instruction is less expressive but easier to grok http://publib.boulder.ibm.com/infocenter/zos/v1r11/topic/com.ibm.zos.r11.ikjc300/ikj4c31062.htm#wq235. Mainframers hate regular expressions which they consider to be some kind of strange voodoo! My intention is to somehow interpret a REXX parse string into a Lua equivilent.