Question

with indy TIdHTTPServer, on the even of OnCommandGet, there is a possiblity to pass to AResponseInfo.ContentStream a stream with the data. which is fine. when can i release that stream? assuming the server can get multi requests, and any request could be handled at given time, and one stream can finish arbitrary to the other.

where could the stream be freed?

code example:

var
  StreamsToFree : TList;

//assume StreamsToFree := TList.create; properly 

procedure TObject.IdHttpServerCommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
stream : TFileStream;
begin
  stream := TFileSTream.create('file.name');
  AResponseInfo.ContentStream := stream;
  AResponseInfo.ResponseNo := 200;
  StreamsToFree.Add(generateReceiptXML);  
end;

When can the stream be freed? on what even, and how do we know the IdHttpServer , finished its transfer?

Was it helpful?

Solution

When you assign it to the ContentStream property, Indy becomes the owner of your stream and will free it when it's no longer needed.

Edit: Assuming you leave FreeContentStream property set to True (which is the default).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top