Monday, November 08, 2010 at 12:07 AM.
system.verbs.builtins.webserver.util.parseHeaders
on parseHeaders (response, adrHeaderTable) { <<Thursday, November 11, 1999 at 3:07:37 AM by AR <<Implemented as a kernel script in Frontier 6.1. <<Old code <<on parseHeaders (response, adrHeaderTable) <<Script: system.verbs.builtins.webserver.util.parseHeaders; Version 1; Date: Thu, 14 May 1998 00:09:29 GMT; ID: RAB <<March 12, 1998 at 5:19:47 PM by WMF <<This script will parse the headers of an HTTP request or response into the given table <<It returns the first line of the request/response <<local (firstLine) <<local (headers = string.mid (response, 0, string.patternmatch ("\r\n\r\n", response) ) ) <<local (i, headerLine, headerName, headerValue) << <<headers = string.replaceAll (headers, "\r\n", cr) <<firstLine = string.nthField (headers, cr, 1) <<if not defined (adrHeaderTable^) <<new (tableType, adrHeaderTable) <<for i =2 to string.countFields (headers, cr) <<headerLine = string.nthField (headers, cr, i) <<headerName = string.nthField (headerLine, ':', 1) <<headerValue = string.popLeading(string.delete (headerLine, 1, sizeOf(headerName)+1), ' ') <<if !defined (adrHeaderTable^.[headerName]) <<adrHeaderTable^.[headerName] = headerValue <<else // in case of duplicate headers, make a list <<if typeOf(adrHeaderTable^.[headerName]) == listType <<adrHeaderTable^.[headerName] = adrHeaderTable^.[headerName] + {headerValue} <<else <<adrHeaderTable^.[headerName] = {adrHeaderTable^.[headerName], headerValue} << <<return (firstLine) kernel (webserver.parseheaders)} <<bundle //test code <<local (ix, ct = clock.ticks ()) <<for ix = 1 to 10 <<local (t); new (tableType, @t) <<parseHeaders (string (scratchpad.testRequest), @t) <<ct = clock.ticks () - ct <<dialog.notify ("Ticks: " + ct) <<bundle //timing code <<local (i, ct = clock.ticks ()) <<for i = 1 to 100 <<local (t); new (tableType, @t) <<parseHeaders (string (scratchpad.testrequest), @t) <<msg ((clock.ticks () - ct ) / 100.0)
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.