Revision: 4477 Author: hans URL: http://bknr.net/trac/changeset/4477
New API for extending request processing without interferring with Hunchentoot's internal variable binding, provided by Frode V. Fjeld.
U trunk/thirdparty/hunchentoot/doc/index.xml U trunk/thirdparty/hunchentoot/packages.lisp U trunk/thirdparty/hunchentoot/request.lisp
Modified: trunk/thirdparty/hunchentoot/doc/index.xml =================================================================== --- trunk/thirdparty/hunchentoot/doc/index.xml 2009-11-25 17:03:40 UTC (rev 4476) +++ trunk/thirdparty/hunchentoot/doc/index.xml 2009-11-30 13:24:17 UTC (rev 4477) @@ -1594,17 +1594,33 @@ </clix:returns> clix:description This function is called by clix:refPROCESS-CONNECTION</clix:ref> -after the incoming headers have been read. It selects and calls a -<a href="#handlers">handler</a> and sends the output of this handler -to the client. It also sets up simple error handling for the request -handler. Note that clix:refPROCESS-CONNECTION</clix:ref> is called -once per connection and loops in case of a persistent connection +after the incoming headers have been read. It +calls clix:refDISPATCH-REQUEST</clix:ref> and sends its output to +the client. It also sets up simple error handling for the request +handler. +<p> +The return value of this function is ignored. +</p> + </clix:description> + </clix:function> + + <clix:function generic='true' name='dispatch-request'> + clix:lambda-listrequest + </clix:lambda-list> + clix:returnsnil + </clix:returns> + clix:description +This function is called by clix:refPROCESS-REQUEST</clix:ref>. It +selects and calls a +<a href="#handlers">handler</a> to process the request. +<p> +This might be a good place to introduce around methods which bind +special variables or do other interesting things that are relevant to +the particular request. Note +that clix:refDISPATCH-REQUEST</clix:ref> is called once per +connection and loops in case of a persistent connection, while clix:refPROCESS-REQUEST</clix:ref> is called anew for each request. -<p> -Like clix:refPROCESS-CONNECTION</clix:ref>, this might be a good -place to introduce around methods which bind special variables or do -other interesting things. </p> <p> The return value of this function is ignored.
Modified: trunk/thirdparty/hunchentoot/packages.lisp =================================================================== --- trunk/thirdparty/hunchentoot/packages.lisp 2009-11-25 17:03:40 UTC (rev 4476) +++ trunk/thirdparty/hunchentoot/packages.lisp 2009-11-30 13:24:17 UTC (rev 4477) @@ -168,6 +168,7 @@ "DELETE-AUX-REQUEST-VALUE" "DELETE-SESSION-VALUE" "DISPATCH-EASY-HANDLERS" + "DISPATCH-REQUEST" "ESCAPE-FOR-HTML" "EXECUTE-ACCEPTOR" "GET-PARAMETER"
Modified: trunk/thirdparty/hunchentoot/request.lisp =================================================================== --- trunk/thirdparty/hunchentoot/request.lisp 2009-11-25 17:03:40 UTC (rev 4476) +++ trunk/thirdparty/hunchentoot/request.lisp 2009-11-30 13:24:17 UTC (rev 4477) @@ -95,21 +95,22 @@ can subclass REQUEST in order to implement your own behaviour. See the REQUEST-CLASS slot of the ACCEPTOR class."))
+(defgeneric dispatch-request (request) + (:documentation "This function is called by PROCESS-REQUEST. It +selects and calls a handler to process the request. + +This might be a good place to introduce around methods which bind +special variables or do other interesting things that are relevant to +the particular request. Note that DISPATCH-REQUEST is called once per +connection and loops in case of a persistent connection, while +PROCESS-REQUEST is called anew for each request.")) + (defgeneric process-request (request) (:documentation "This function is called by PROCESS-CONNECTION after -the incoming headers have been read. It selects and calls a handler -and sends the output of this handler to the client using START-OUTPUT. -It also sets up simple error handling for the request handler. Note -that PROCESS-CONNECTION is called once per connection and loops in -case of a persistent connection while PROCESS-REQUEST is called anew -for each request. +the incoming headers have been read. It calls DISPATCH-REQUEST and +sends its output to the client. It also sets up simple error handling +for the request handler."))
-Like PROCESS-CONNECTION, this might be a good place to introduce -around methods which bind special variables or do other interesting -things. - -The return value of this function is ignored.")) - (defun convert-hack (string external-format) "The rfc2388 package is buggy in that it operates on a character stream and thus only accepts encodings which are 8 bit transparent. @@ -210,6 +211,12 @@ ;; we assume it's not our fault... (setf (return-code*) +http-bad-request+)))))
+(defmethod dispatch-request (request) + "Standard implementation of dispatching a request to the appropriate +handler." + (funcall (acceptor-request-dispatcher *acceptor*) + request)) + (defmethod process-request (request) "Standard implementation for processing a request. You should not change or replace this functionality unless you know what you're @@ -227,7 +234,7 @@ ;; skip dispatch if bad request (when (eql (return-code *reply*) +http-ok+) ;; now do the work - (funcall (acceptor-request-dispatcher *acceptor*) *request*))))) + (dispatch-request request))))) (when error (setf (return-code *reply*) +http-internal-server-error+))