Re: TIdMimeTable.BuildCache problem

Giganews Newsgroups
Subject: Re: TIdMimeTable.BuildCache problem
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Wed, 30 Sep 2009

"Farshad Mohajeri" <farshad…@fmsoft.net> wrote in message
news:A4EC1A6AC592E340farshad…@fmsoft.net...

> My workaround is to make an explicit call to BuildCache() before
> I activate my HTTP server.

There are a few alternative solitions:

1) change the TIdCustomHTTPServer.InitComponent() method to pass True
instead of False to the AutoFill parameter of TIdMimeTable's constructor.
However, whether you build the cache manually, or have the server do it
automatically, that will not prevent BuildCache() from being called on a
per-file basis in all situations.  If you ever serve a file extension that
is not known to the OS at server activation, that would cause
FFileExt.IndexOf() inside of TIdMimeTable.GetFileMIMEType() to return -1,
which will call BuildCache() again.

2) Remove TIdMimeTable from TIdCustomHTTPServer and change ServerFile() to
use the IdGlobalProtocols.GetMIMETypeFromFile() function instead.  Not
necessarily the best idea for performance, though, which is probably why
TIdCustomHTTPServer has a reusable TIdMimeTable object to begin with.

3) change the FMIMEList and FFileExt members of TIdMimeTable from
TStringList to TIdThreadSafeStringList.  Or better, create a separate
TIdThreadSafeMimeTable type of class instead, since TIdMimeTable is used in
other areas of Indy where thread-safety is not as much an issue (those areas
use IdGlobalProtocols.GetMIMETypeFromFile() instead of TIdMimeTable
directly).

> Indy version: 10.2.3

That is a very old verison.  The current version is 10.5.7.

--
Remy Lebeau (TeamB)

Replies

In response to

TIdMimeTable.BuildCache problem posted by Farshad Mohajeri on Wed, 30 Sep 2009