Monday, November 08, 2010 at 12:06 AM.
system.verbs.builtins.webserver.data.responders.CGI.methods.any
<<Script: system.verbs.builtins.webserver.data.responders.CGI.methods.any; Version 1; Date: Wed, 20 May 1998 00:33:42 GMT; ID: RAB <<removed call to webserver.init on any (adrParams) { <<we're using compatibility mode for speed local { adrHeaderTable = @adrParams^.requestHeaders}; local (s, paramTable); local (request = adrparams^.request); local (lowerRequest = string.lower (request)); local (frontierPath = frontier.getProgramPath ()); local (authorization); new (tableType, @paramTable); paramTable.fullRequest = string (request); request = string.replaceAll (request, cr + lf, cr); lowerRequest = string.lower (request); on decodePassword (s) { local (val, usr, pass); val = string (base64.decode (s)); usr = string.nthField (val, ":", 1); pass = string.nthField (val, ":", 2); return ({usr, pass})}; on parseAuthorization (s) { local (basicStart = string.patternMatch ("Basic", s)); if basicStart { s = string.mid (s, basicStart + 6, infinity); return (decodePassword (s))} else { return ({"",""})}}; bundle { // Set up cgi parameters table. <<March 05, 1998 at 8:38:22 PM by WMF <<This script needs to do less work because the server does more work <<on getField (fieldName) <<local (ix, x) <<fieldName = string.lower (fieldName + ":") <<ix = string.patternMatch (fieldName, lowerRequest) <<if ix < 1 <<return ("") <<x = string.mid (request, ix, infinity) <<x = string.nthField (x, cr, 1) <<x = string.delete (x, 1, sizeOf (fieldName) + 1) <<x = string.popLeading (x, ' ') <<return (x) on getField (fieldName) { // March 05, 1998 at 8:29:07 PM by WMF if defined (adrParams^.requestHeaders.[fieldName]) { return (adrParams^.requestHeaders.[fieldName])} else { return ("")}}; <<paramTable.scriptName = string.nthField (request, cr, 1) <<paramTable.scriptName = string.nthField (paramTable.scriptName, ' ', 2) paramTable.scriptName = adrParams^.path; paramTable.scriptName = string.urlDecode (paramTable.scriptName); <<if paramTable.scriptName contains "?" <<paramTable.httpSearchArgs = string.nthField (paramTable.scriptName, "?", 2) <<paramTable.scriptName = string.nthField (paramTable.scriptName, "?", 1) paramTable.httpSearchArgs = adrParams^.searchArgs; <<if paramTable.scriptName contains "$" <<paramTable.pathArgs = string.nthField (paramTable.scriptName, "$", 2) <<paramTable.scriptName = string.nthField (paramTable.scriptName, "$", 1) paramTable.pathArgs = adrParams^.pathArgs; paramTable.accept = getField ("accept"); paramTable.acceptCharset = getField ("accept-charset"); paramTable.acceptEncoding = getField ("accept-encoding"); paramTable.acceptLanguage = getField ("accept-language"); paramTable.appName = file.fileFromPath (frontierPath); paramTable.connection = getField ("connection"); paramTable.connectionID = adrparams^.stream; paramTable.contentType = getField ("content-type"); paramTable.fromUser = getField ("from"); paramTable.host = getField ("host"); paramTable.method = adrParams^.method; <<paramTable.postArgs = "" <<paramTable.postArgs = string.popTrailing (string.delete (request, 1, string.patternMatch ("\r\r", request) +1), cr) paramTable.postArgs = adrparams^.requestBody; <<theoretically, we should only parse the POST args if the content-type says that it's form data <<however, this would probably be too strict and break a bunch of stuff if paramTable.postArgs != "" { // parse post arguments into a table. new (tableType, @paramTable.argTable); webserver.parseArgs (paramTable.postArgs, @paramTable.argTable)}; paramTable.referer = getField ("referer"); paramTable.serverName = tcp.addressDecode (tcp.myAddress()); paramTable.serverPath = frontierPath; <<paramTable.serverPort = parentof (this^)^.port paramTable.serverPort = adrParams^.port; paramTable.userAgent = getField ("user-agent"); paramTable.userName = ""; paramTable.password = ""; authorization = getField ("authorization"); if authorization != "" { local (authorizationList = parseAuthorization (authorization)); paramTable.userName = authorizationList [1]; paramTable.password = authorizationList [2]}; paramTable.clientIP = adrparams^.client; if webserver.getPref ("fluseDNS") { try { paramTable.clientAddress = tcp.addressToName (tcp.addressEncode (adrparams^.client))} else { paramTable.clientAddress = adrparams^.client}} else { paramTable.clientAddress = adrparams^.client}}; return (webserver.handler (@paramTable))}
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.