读DataSnap源代码(四)
继续篇中的
function TCustomWebDispatcher.DispatchAction(Request: TWebRequest;
Response: TWebResponse): Boolean;
var
I: Integer;
Action, Default: TWebActionItem;
Dispatch: IWebDispatch;
begin
FRequest := Request;
FResponse := Response;
I := ;
Default := nil;
if Response.Sent then
begin
Result := True;
{ Note that WebSnapSvr enabled apps have no way to mark response as sent }
Exit;
end;
Result := DoBeforeDispatch(Request, Response) or Response.Sent;
while not Result and (I < FActions.Count) do
begin
Action := FActions[I];
Result := Action.DispatchAction(Request, Response, False);
if Action.Default then Default := Action;
Inc(I);
end;
// Dispatch to self registering components
I := ;
while not Result and (I < FDispatchList.Count) do
begin
if Supports(IInterface(FDispatchList.Items[I]), IWebDispatch, Dispatch) then
begin
Result := DispatchHandler(Self, Dispatch,
Request, Response, False);
end;
Inc(I);
end; if not Result and Assigned(Default) then
Result := Default.DispatchAction(Request, Response, True);
if Result and not Response.Sent then
Result := DoAfterDispatch(Request, Response); end;
在第26行代码之前,是执行WebModule中的Action, 然后是遍例WebModule上的Component, 只要支持IWebDispatch,都有机会处理WEB请求。
当然就包括了 TDSHTTPWebDispatcher = class(TDSHTTPServerTransport, IWebDispatch)。 继续代码:
function DispatchHandler(Sender: TObject; Dispatch: IWebDispatch; Request: TWebRequest; Response: TWebResponse;
DoDefault: Boolean): Boolean;
begin
Result := False;
if (Dispatch.Enabled and ((Dispatch.MethodType = mtAny) or
(Request.MethodType = Dispatch.MethodType)) and
Dispatch.Mask.Matches(string(Request.InternalPathInfo))) then
begin
Result := Dispatch.DispatchRequest(Sender, Request, Response);
end;
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 do
begin
{ Default to 500, like web services. }
Response.StatusCode := 500;
Result := True;
end;
end;
except
{ Swallow any unexpected exception, it will bring down some web servers }
Result := False;
end;
finally
{ Reset current DataSnapWebModule }
DataSnapWebModule := nil;
end;
end;
至此,WEB请求转入到WebModule中的TDSHTTPWebDispatcher来处理了。
读DataSnap源代码(四)的更多相关文章
- 读DataSnap源代码(一)
Delphi的DataSnap用了一段时间了,但一直感觉有些地方还不够了解,所以花时间阅读了源代码,特作此烂笔头. Datasnap是在之前的WebBorker基础上搭建的,DataSnap向导自动生 ...
- 读DataSnap源代码(五)
function TDSHTTPWebDispatcher.DispatchRequest(Sender: TObject; Request: TWebRequest; Response: TWebR ...
- 读DataSnap源代码(六)
具体分析一下DataSanp App与Rest, WebBroker App的不同,先看TDSHTTPService. **************************************** ...
- 读DataSnap源代码(三)
function TWebRequestHandler.HandleRequest(Request: TWebRequest; Response: TWebResponse): Boolean; va ...
- 读DataSnap源代码(二)
program Project1; {$APPTYPE GUI} {$R *.dres} uses Vcl.Forms, Web.WebReq, IdHTTPWebBrokerBridge, Form ...
- 读Flask源代码学习Python--config原理
读Flask源代码学习Python--config原理 个人学习笔记,水平有限.如果理解错误的地方,请大家指出来,谢谢!第一次写文章,发现好累--!. 起因 莫名其妙在第一份工作中使用了从来没有接 ...
- session自己定义存储,怎样更好地进行session共享;读tomcat7源代码,org.apache.catalina.session.FileStore可知
session自己定义存储.怎样更好地进行session共享: 读tomcat源代码,org.apache.catalina.session.FileStore可知 一.详见: 方法1 public ...
- dotnet 读 WPF 源代码笔记 布局时 Arrange 如何影响元素渲染坐标
大家是否好奇,在 WPF 里面,对 UIElement 重写 OnRender 方法进行渲染的内容,是如何受到上层容器控件的布局而进行坐标偏移.如有两个放入到 StackPanel 的自定义 UIEl ...
- dotnet 读 WPF 源代码笔记 渲染收集是如何触发
在 WPF 里面,渲染可以从架构上划分为两层.上层是 WPF 框架的 OnRender 之类的函数,作用是收集应用程序渲染的命令.上层将收集到的应用程序绘制渲染的命令传给下层,下层是 WPF 的 GF ...
随机推荐
- Linux下的shell与make
Linux下的shell与make 一.shell 1.1 什么是shell ● 用户与Linux的接口 ● 命令解释器 ● 支持多用户 ● 支持复杂的编程语言 ● Shell有很多种,如:csh,t ...
- LeetCode—66、88、118、119、121 Array(Easy)
66. Plus One Given a non-negative integer represented as a non-empty array of digits, plus one to th ...
- Python基础5--字符串
1 find().rfind().index().rindex().count() s = "this apple is red apple" s.find("apple ...
- python的time模块
#encoding=utf-8 import time # 返回时间戳 print time.time() # 延迟运行单位为s,如下为延迟3s time.sleep(3) # 转换时间戳为时间元组( ...
- 路径问题 :<c:url >的作用
最近的项目一直报这样的错 可是本地启动 又没问题,xshell查看日志 没有错误日志,找了好久都没想到错误原因.一位大佬几分钟就找到原因了有点扎心. 首先说一下解决问题的思路.首先报错是4开头,说明是 ...
- C++---String类小结
本随笔是我自己在敲代码的时候一些感受,可能有的地方简略了,还有部分是融合了一点其他资料上的知识点,如有错误欢迎指出,谢谢_(:°з」∠)_ string类是C++中常用的字符串类型,比之普通的字符串要 ...
- MongDB篇,第一章:数据库知识1
MongDB 数据库知识1 程序 = 数据结构 + 算法 数据存储阶段 1,文件管理阶段 (.txt .doc .xls) 优点: 数据可以长期保存:可以存储大量的数据:使用简单 缺点 ...
- 九度OJ1049题-去特定字符(和1111题特别像)
题目1049:字符串去特定字符 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:11329 解决:5169 题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: ...
- golang 六宫格、九宫格头像生成
图片示例就不传了,在原WordPress上. //Merge6Grid 6宫格 //rule NO1:至少3张图 最多6张图 // NO2:第一张大小 60*60 其他大小 28*28 间隔4px 合 ...
- Unity 3D-Canvas画布的三种模式
Unity开发VR之Vuforia 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...