Read Datasnap source code (IV)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.