[Lazarus] CGI Response.ContentStream client break

Leonardo M. Ramé l.rame at griensu.com
Thu Jul 3 22:28:41 CEST 2014


On 2014-07-03 17:20:53 -0300, silvioprog wrote:
> 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;
> 

Thanks Silvio, it seems to work.

-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com




More information about the Lazarus mailing list