【问题标题】:Earliest moment to abandon POST request in webservice?最早放弃网络服务中的 POST 请求?
【发布时间】:2016-04-29 10:04:04
【问题描述】:

我的网络服务中的“安全措施”之一是阻止大文件上传。
当发送的文件太大时,我想尽快取消文件上传请求。

由于文件上传的请求无论如何都会是最大的请求,我目前在TWebModuleBeforeDispatch 处理程序中有此代码:

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

【问题讨论】:

    标签: web-services delphi indy indy10 delphi-10-seattle


    【解决方案1】:

    对于 Indy,TCustomWebDispatcher.BeforeDispatch 事件为时已晚,因为已在 TIdCustomHttpServer.DoExecute 中检索到发布数据流。您可以使用TIdCustomHTTPServer.OnHeadersAvailable 事件(之前触发)通过将VContinueProcessing 设置为False 来避免它。

    【讨论】:

    • OnHeadersAvailable 设置VContinue=False 时,您可以使用TIdCustomHTTPServer.OnHeadersBlocked 事件来自定义发送回客户端的响应。默认情况下,发送403 Forbidden 响应。在这种情况下,413 Payload Too Large 会更合适。
    猜你喜欢
    • 1970-01-01
    • 2012-11-17
    • 2019-07-30
    • 2018-04-16
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    相关资源
    最近更新 更多