Monday, November 08, 2010 at 12:06 AM.
system.verbs.builtins.webserver.dispatch
on dispatch (adrParamTable) {
<<Thursday, November 11, 1999 at 3:08:16 AM by AR
<<Implemented as a kernel script in Frontier 6.1.
<<Old code
<<Wed, Jun 10, 1998 at 2:36:20 PM by PBS
<<Get responder name from user.webserver.responders table, not from actual responder table.
<<Script: system.verbs.builtins.webserver.dispatch; Version 2; Date: Thu, 21 May 1998 17:52:33 GMT; ID: RAB
<<Allow the condition to be a script
<<Script: system.verbs.builtins.webserver.dispatch; Version 1; Date: Wed, 13 May 1998 01:12:57 GMT; ID: RAB
<<on dispatch (adrParamTable)
<<March 19, 1998 at 5:26:27 PM by WMF
<<A common script that dispatches a request to the proper responder
<<local (compatibility, method, methodAdr, filterAdr, responderTableAdr)
<<local (i) //used for indexing
<<
<<on isScript (name)
<<local (objType)
<<if (typeOf (name^) == binaryType)
<<objType = getBinaryType (name^)
<<else
<<objType = typeOf (name^)
<<if (objType == scriptType) or (objType == codeType)
<<return (true)
<<return (false)
<<
<<bundle //call pre-filters
<<for i = 1 to sizeOf (user.webserver.preFilters)
<<try
<<filterAdr = @user.webserver.preFilters[i]
<<if typeOf (filterAdr^) == addressType
<<filterAdr = filterAdr^
<<filterAdr^ (adrParamTable)
<<else
<<log.add ("Pre filter error: " + @user.webserver.preFilters[i] + ": " + tryError, "webserver")
<<
<<determine which responder should handle this request
<<local (responder = webserver.getPref("defaultResponder"))
<<for i =1 to sizeOf(user.webserver.responders)
<<responderTableAdr = webserver.util.getResponderTableAdr (nameOf(user.webserver.responders[i]))
<<try //this handles ignoring a bad address dereference on the responderTableAdr
<<if defined (responderTableAdr^.condition)
<<if (defined (responderTableAdr^.enabled) && responderTableAdr^.enabled)
<<try
<<with adrParamTable^, adrParamTable^.requestHeaders // allow conditions to see headers easily
<<if (typeOf (responderTableAdr^.condition) == scriptType) or (typeOf (responderTableAdr^.condition) == codeType)
<<if responderTableAdr^.condition (adrParamTable)
<<responder = nameOf (user.webserver.responders [i]) //PBS 6/10/98: get responder name from user.webserver.responders table.
<<break
<<else
<<if evaluate (responderTableAdr^.condition)
<<responder = nameOf (user.webserver.responders [i]) //PBS 6/10/98: get responder name from user.webserver.responders table.
<<break
<<
<<adrParamTable^.responder = responder
<<adrParamTable^.responderTableAdr = webserver.util.getResponderTableAdr (responder)
<<adrParamTable^.code = 200 // fill in default values
<<adrParamTable^.responseBody = ""
<<new (tableType, @adrParamTable^.responseHeaders)
<<
<<dispatch the request to the correct responder method
<<
<<method = adrParamTable^.method
<<
<<bundle //handle switching to the any method
<<methodAdr = webserver.util.getMethodAdr (responder, method)
<<if ! defined(methodAdr^)
<<methodAdr = webserver.util.getMethodAdr (responder, "any")
<<if defined (methodAdr^)
<<method = "any" //change from the specific method type to the any method
<<
<<methodAdr = webserver.util.getMethodAdr (responder, method)
<<if defined (methodAdr^) && (isScript (methodAdr))
<<try
<<compatibility = methodAdr^ (adrParamTable) //call the responder
<<if (compatibility == true)
<<call post-filters
<<for i = 1 to sizeOf (user.webserver.postFilters)
<<try
<<filterAdr = @user.webserver.postFilters[i]
<<if typeOf (filterAdr^) == addressType
<<filterAdr = filterAdr^
<<filterAdr^ (adrParamTable)
<<else
<<log.add ("Post filter error: " + @user.webserver.postFilters[i] + ": " + tryError, "webserver")
<<return (webserver.util.buildResponse (adrParamTable^.code, @adrParamTable^.responseHeaders, adrParamTable^.responseBody))
<<else
<<do the hack for the old CGI framework
<<return (compatibility)
<<else
<<log.add ("Responder method error: " + methodAdr + ": " + tryError, "webserver")
<<semaphores.unlock ("")
<<return (webserver.util.buildResponse (500, nil, webserver.util.buildErrorPage ("500 Server Error", tryError)))
<<else // this service doesn't support this method
<<local (allowedMethods, methodTableAdr)
<<responderTableAdr = webserver.util.getResponderTableAdr (responder)
<<methodTableAdr = @responderTableAdr^.methods
<<if typeOf (methodTableAdr^) == addressType
<<methodTableAdr = methodTableAdr^
<<allowedMethods = ""
<<for i =1 to sizeOf (methodTableAdr^)
<<allowedMethods = allowedMethods + ", " + nameOf(methodTableAdr^[i])
<<new (tableType, @badMethodHeaders)
<<badMethodHeaders.Allow = allowedMethods
<<return (webserver.util.buildResponse (405, @badMethodHeaders, webserver.util.buildErrorPage ("405 Method Not Allowed", method + " isn't allowed on this object.")))
kernel (webserver.dispatch)}
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.