我的网络服务中的“安全措施”之一是阻止大文件上传。
发送太大文件时,我想尽快取消文件上传请求。
由于带有文件上传的请求无论如何都会是最大的请求,因此我目前在BeforeDispatch
的TWebModule
处理程序中具有以下代码:
procedure TWebModuleWebServices.WebModuleBeforeDispatch(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
// Request that are too large are going to be dropped silently:
if Request.ContentLength > cMaxContentSize then
begin
Handled := true;
Exit;
end;
是BeforeDispatch处理程序是该测试最早的阶段,还是有更好的地方?
Web服务是围绕
TIdHTTPWebBrokerBridge
构建的(= class(TIdCustomHTTPServer)
,请参见IdHTTPWebBrokerBridge.pas
)
最佳答案
使用Indy时,TCustomWebDispatcher.BeforeDispatch
事件为时已晚,因为已经在TIdCustomHttpServer.DoExecute
中检索到了发布数据流。您可以通过将TIdCustomHTTPServer.OnHeadersAvailable
设置为VContinueProcessing
来使用False
事件(该事件较早触发)来避免该事件。
关于web-services - 最早放弃Web服务中的POST请求吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36935412/