[Lazarus] CGI Response.ContentStream client break

silvioprog silvioprog at gmail.com
Thu Jul 3 22:20:53 CEST 2014


2014-07-03 16:51 GMT-03:00 Leonardo M. Ramé <l.rame at griensu.com>:

> Hi, I have a CGI program that serves some files using this code in an
> action:
>
> AResponse.ContentStream := TFileStream.Create(lImagePath, fmOpenRead);
>
> The problem I'm facing is that some times the client breaks the
> connection to the server, aparently leaving the file open. If the client
> tries to download the file again, a code 500 is returned.
>
> Is there a way to detect the connection break and destroy the stream
> gracefully?.
>

You can use the FreeContentStream property and free your stream manually,
e.g.:

var
  f: TFileStream;
begin
  f := TFileStream.Create(...);
  try
    HttpResponse.FreeContentStream := False;
    HttpResponse.ContentType := 'application/octet-stream';
    HttpResponse.ContentStream := f;
    HttpResponse.SendContent;
  finally
    f.Free;
  end;
end;

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140703/73b271bc/attachment-0003.html>


More information about the Lazarus mailing list