idHTTPServer - ServeFile trying to alocate whole download files in memory...

Giganews Newsgroups
Subject: idHTTPServer - ServeFile trying to alocate whole download files in memory...
Posted by:  nars (no@spam.plz)
Date: Wed, 15 Mar 2006

Hello,

I'm trying to make a small http server and to serve files I used something
like:

procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo:
TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var LocalDoc : string;
begin
  LocalDoc := ExpandFilename(root + ARequestInfo.Document);
  ...
    if AnsiSameText(ARequestInfo.Command, 'HEAD') then
    begin
      AResponseInfo.ResponseNo := 200;
      AResponseInfo.ContentType :=
IdHTTPServer1.MIMETable.GetFileMIMEType(LocalDoc);
      AResponseInfo.ContentLength := FileSizeByName(LocalDoc);
    end
    else
    begin
      AResponseInfo.ContentType := ''; //servefile will add mime if
ContentType=''
      AResponseInfo.ServeFile(AContext, LocalDoc);
    end;
  ...
end;

The problem is that when downloading big files from this server it will try
to alocate whole file in memory... I see on taskmanager memory used by my
app increasing to the download file size... I have also tried to create a
stream and pass it to AResponseInfo.ContentStream instead of using ServeFile
function but same behaviour... any idea how to fix/workaround this problem?

Regards

Replies