Continue in the article
1 functiontcustomwebdispatcher.dispatchaction (request:twebrequest;2 response:twebresponse): Boolean;3 var4 I:integer;5 Action, Default:twebactionitem;6 Dispatch:iwebdispatch;7 begin8Frequest: =Request;9Fresponse: =Response;TenI: =0; OneDefault: =Nil; A ifResponse.sent Then - begin -Result: =True; the {Note that websnapsvr enabled apps has no to mark response as sent} - Exit; - End; -Result: = Dobeforedispatch (Request, Response)orresponse.sent; + while notResult and(I < Factions.count) Do - begin +Action: =Factions[i]; AResult: =action.dispatchaction (Request, Response, False); at ifAction.default ThenDefault: =Action; - INC (I); - End; - //Dispatch to self registering components -I: =0; - while notResult and(I < Fdispatchlist.count) Do in begin - ifSupports (IInterface (Fdispatchlist.items[i]), Iwebdispatch, Dispatch) Then to begin +Result: =Dispatchhandler (self, Dispatch, - Request, Response, False); the End; * INC (I); $ End;Panax Notoginseng - if notResult andAssigned (Default) Then theResult: =default.dispatchaction (Request, Response, True); + ifResult and notResponse.sent Then AResult: =Doafterdispatch (Request, Response); the + End;
Before the 26th line of code, the action in Webmodule is executed, and then the component on the Webmodule, as long as Iwebdispatch is supported, there is a chance to process the Web request.
Of course, Tdshttpwebdispatcher = Class (Tdshttpservertransport, Iwebdispatch) is included. Continuation code:
1 functionDispatchhandler (sender:tobject; Dispatch:iwebdispatch; Request:twebrequest; Response:twebresponse;2 Dodefault:boolean): Boolean;3 begin4Result: =False;5 if(dispatch.enabled and((Dispatch.methodtype = Mtany)or6(Request.methodtype = Dispatch.methodtype)) and7Dispatch.Mask.Matches (string(Request.internalpathinfo))) Then8 begin9Result: =dispatch.dispatchrequest (Sender, Request, Response);Ten End; One End;
function Tdshttpwebdispatcher.dispatchrequest (sender:tobject; Request:twebrequest; Response:twebresponse): Boolean;begin Try If Owner is Twebmodule then datasnapwebmodule: = Twebmodule ( Owner); Try try requiresserver; Tdshttpserverwebbroker (Self.fhttpserver). Dispatchdatasnap (Request, Response); Result: = True; Except on e:exception does begin {Default to $, like Web services.} Response.statuscode: = $; Result: = True; End; End; Except {Swallow Any unexpected exception, it would bring down some Web servers} Result: = False; End; Finally {Reset current datasnapwebmodule} datasnapwebmodule: = nil; End;end;
At this point, the Web request was transferred to the Tdshttpwebdispatcher in Webmodule to be processed.
Read Datasnap source code (IV)