unit Sparkle.Module.Static;

interface

uses
  Generics.Collections, System.SysUtils, System.Classes,
  Sparkle.HttpServer.Context,
  Sparkle.HttpServer.Module;

type
  TStaticModule = class(THttpServerModule)
  private
    FRootDir: string;
    FContentTypes: TDictionary<string, string>;
    FIndexFiles: TStrings;
    FLastModified: Boolean;
    procedure ProcessFile(C: THttpServerContext; const RelativePath: string);
    function ProcessIndex(C: THttpServerContext; const RelativePath: string): Boolean;
    procedure DefineContentType(C: THttpServerContext; const FileName: string);
    function FindContentType(const FileName: string): string;
    procedure AddApplicationContentTypes;
  protected
    function FullFileName(const RelativePath: string): string;
    function CreateFileStream(const RelativePath: string): TStream; virtual;
    function IsValidFile(const RelativePath: string): Boolean; virtual;
    function IsValidDir(const RelativePath: string): Boolean; virtual;
    procedure NotProcessed(C: THttpServerContext); virtual;
    procedure ProcessRequest(const C: THttpServerContext); override;
  public
    constructor Create(const ABaseUri: string); overload; override;
    constructor Create(const ABaseUri, ARootDir: string); reintroduce; overload;
    destructor Destroy; override;

    property RootDir: string read FRootDir write FRootDir;
    property IndexFiles: TStrings read FIndexFiles;
    property LastModified: Boolean read FLastModified write FLastModified;
  end;

implementation

uses
  Bcl.Utils,
  System.IOUtils;

{ TStaticModule }

constructor TStaticModule.Create(const ABaseUri: string);
begin
  inherited Create(ABaseUri);
  FIndexFiles := TStringList.Create;
  FIndexFiles.Add('index.html');
  FIndexFiles.Add('index.htm');
  FContentTypes := TDictionary<string, string>.Create;
  FLastModified := True;

  AddApplicationContentTypes;
  FContentTypes.AddOrSetValue('.adp', 'audio/adpcm');
  FContentTypes.AddOrSetValue('.au', 'audio/basic');
  FContentTypes.AddOrSetValue('.snd', 'audio/basic');
  FContentTypes.AddOrSetValue('.mid', 'audio/midi');
  FContentTypes.AddOrSetValue('.midi', 'audio/midi');
  FContentTypes.AddOrSetValue('.kar', 'audio/midi');
  FContentTypes.AddOrSetValue('.rmi', 'audio/midi');
  FContentTypes.AddOrSetValue('.mp4a', 'audio/mp4');
  FContentTypes.AddOrSetValue('.m4a', 'audio/mp4');
  FContentTypes.AddOrSetValue('.mpga', 'audio/mpeg');
  FContentTypes.AddOrSetValue('.mp2', 'audio/mpeg');
  FContentTypes.AddOrSetValue('.mp2a', 'audio/mpeg');
  FContentTypes.AddOrSetValue('.mp3', 'audio/mpeg');
  FContentTypes.AddOrSetValue('.m2a', 'audio/mpeg');
  FContentTypes.AddOrSetValue('.m3a', 'audio/mpeg');
  FContentTypes.AddOrSetValue('.oga', 'audio/ogg');
  FContentTypes.AddOrSetValue('.ogg', 'audio/ogg');
  FContentTypes.AddOrSetValue('.spx', 'audio/ogg');
  FContentTypes.AddOrSetValue('.s3m', 'audio/s3m');
  FContentTypes.AddOrSetValue('.sil', 'audio/silk');
  FContentTypes.AddOrSetValue('.uva', 'audio/vnd.dece.audio');
  FContentTypes.AddOrSetValue('.uvva', 'audio/vnd.dece.audio');
  FContentTypes.AddOrSetValue('.eol', 'audio/vnd.digital-winds');
  FContentTypes.AddOrSetValue('.dra', 'audio/vnd.dra');
  FContentTypes.AddOrSetValue('.dts', 'audio/vnd.dts');
  FContentTypes.AddOrSetValue('.dtshd', 'audio/vnd.dts.hd');
  FContentTypes.AddOrSetValue('.lvp', 'audio/vnd.lucent.voice');
  FContentTypes.AddOrSetValue('.pya', 'audio/vnd.ms-playready.media.pya');
  FContentTypes.AddOrSetValue('.ecelp4800', 'audio/vnd.nuera.ecelp4800');
  FContentTypes.AddOrSetValue('.ecelp7470', 'audio/vnd.nuera.ecelp7470');
  FContentTypes.AddOrSetValue('.ecelp9600', 'audio/vnd.nuera.ecelp9600');
  FContentTypes.AddOrSetValue('.rip', 'audio/vnd.rip');
  FContentTypes.AddOrSetValue('.weba', 'audio/webm');
  FContentTypes.AddOrSetValue('.aac', 'audio/x-aac');
  FContentTypes.AddOrSetValue('.aif', 'audio/x-aiff');
  FContentTypes.AddOrSetValue('.aiff', 'audio/x-aiff');
  FContentTypes.AddOrSetValue('.aifc', 'audio/x-aiff');
  FContentTypes.AddOrSetValue('.caf', 'audio/x-caf');
  FContentTypes.AddOrSetValue('.flac', 'audio/x-flac');
  FContentTypes.AddOrSetValue('.mka', 'audio/x-matroska');
  FContentTypes.AddOrSetValue('.m3u', 'audio/x-mpegurl');
  FContentTypes.AddOrSetValue('.wax', 'audio/x-ms-wax');
  FContentTypes.AddOrSetValue('.wma', 'audio/x-ms-wma');
  FContentTypes.AddOrSetValue('.ram', 'audio/x-pn-realaudio');
  FContentTypes.AddOrSetValue('.ra', 'audio/x-pn-realaudio');
  FContentTypes.AddOrSetValue('.rmp', 'audio/x-pn-realaudio-plugin');
  FContentTypes.AddOrSetValue('.wav', 'audio/x-wav');
  FContentTypes.AddOrSetValue('.xm', 'audio/xm');
  FContentTypes.AddOrSetValue('.cdx', 'chemical/x-cdx');
  FContentTypes.AddOrSetValue('.cif', 'chemical/x-cif');
  FContentTypes.AddOrSetValue('.cmdf', 'chemical/x-cmdf');
  FContentTypes.AddOrSetValue('.cml', 'chemical/x-cml');
  FContentTypes.AddOrSetValue('.csml', 'chemical/x-csml');
  FContentTypes.AddOrSetValue('.xyz', 'chemical/x-xyz');
  FContentTypes.AddOrSetValue('.otf', 'font/opentype');
  FContentTypes.AddOrSetValue('.bmp', 'image/bmp');
  FContentTypes.AddOrSetValue('.cgm', 'image/cgm');
  FContentTypes.AddOrSetValue('.g3', 'image/g3fax');
  FContentTypes.AddOrSetValue('.gif', 'image/gif');
  FContentTypes.AddOrSetValue('.ief', 'image/ief');
  FContentTypes.AddOrSetValue('.jpeg', 'image/jpeg');
  FContentTypes.AddOrSetValue('.jpg', 'image/jpeg');
  FContentTypes.AddOrSetValue('.jpe', 'image/jpeg');
  FContentTypes.AddOrSetValue('.ktx', 'image/ktx');
  FContentTypes.AddOrSetValue('.png', 'image/png');
  FContentTypes.AddOrSetValue('.btif', 'image/prs.btif');
  FContentTypes.AddOrSetValue('.sgi', 'image/sgi');
  FContentTypes.AddOrSetValue('.svg', 'image/svg+xml');
  FContentTypes.AddOrSetValue('.svgz', 'image/svg+xml');
  FContentTypes.AddOrSetValue('.tiff', 'image/tiff');
  FContentTypes.AddOrSetValue('.tif', 'image/tiff');
  FContentTypes.AddOrSetValue('.psd', 'image/vnd.adobe.photoshop');
  FContentTypes.AddOrSetValue('.uvi', 'image/vnd.dece.graphic');
  FContentTypes.AddOrSetValue('.uvvi', 'image/vnd.dece.graphic');
  FContentTypes.AddOrSetValue('.uvg', 'image/vnd.dece.graphic');
  FContentTypes.AddOrSetValue('.uvvg', 'image/vnd.dece.graphic');
  FContentTypes.AddOrSetValue('.djvu', 'image/vnd.djvu');
  FContentTypes.AddOrSetValue('.djv', 'image/vnd.djvu');
//  FContentTypes.AddOrSetValue('.sub', 'image/vnd.dvb.subtitle');
  FContentTypes.AddOrSetValue('.dwg', 'image/vnd.dwg');
  FContentTypes.AddOrSetValue('.dxf', 'image/vnd.dxf');
  FContentTypes.AddOrSetValue('.fbs', 'image/vnd.fastbidsheet');
  FContentTypes.AddOrSetValue('.fpx', 'image/vnd.fpx');
  FContentTypes.AddOrSetValue('.fst', 'image/vnd.fst');
  FContentTypes.AddOrSetValue('.mmr', 'image/vnd.fujixerox.edmics-mmr');
  FContentTypes.AddOrSetValue('.rlc', 'image/vnd.fujixerox.edmics-rlc');
  FContentTypes.AddOrSetValue('.mdi', 'image/vnd.ms-modi');
  FContentTypes.AddOrSetValue('.wdp', 'image/vnd.ms-photo');
  FContentTypes.AddOrSetValue('.npx', 'image/vnd.net-fpx');
  FContentTypes.AddOrSetValue('.wbmp', 'image/vnd.wap.wbmp');
  FContentTypes.AddOrSetValue('.xif', 'image/vnd.xiff');
  FContentTypes.AddOrSetValue('.webp', 'image/webp');
  FContentTypes.AddOrSetValue('.3ds', 'image/x-3ds');
  FContentTypes.AddOrSetValue('.ras', 'image/x-cmu-raster');
  FContentTypes.AddOrSetValue('.cmx', 'image/x-cmx');
  FContentTypes.AddOrSetValue('.fh', 'image/x-freehand');
  FContentTypes.AddOrSetValue('.fhc', 'image/x-freehand');
  FContentTypes.AddOrSetValue('.fh4', 'image/x-freehand');
  FContentTypes.AddOrSetValue('.fh5', 'image/x-freehand');
  FContentTypes.AddOrSetValue('.fh7', 'image/x-freehand');
  FContentTypes.AddOrSetValue('.ico', 'image/x-icon');
  FContentTypes.AddOrSetValue('.sid', 'image/x-mrsid-image');
  FContentTypes.AddOrSetValue('.pcx', 'image/x-pcx');
  FContentTypes.AddOrSetValue('.pic', 'image/x-pict');
  FContentTypes.AddOrSetValue('.pct', 'image/x-pict');
  FContentTypes.AddOrSetValue('.pnm', 'image/x-portable-anymap');
  FContentTypes.AddOrSetValue('.pbm', 'image/x-portable-bitmap');
  FContentTypes.AddOrSetValue('.pgm', 'image/x-portable-graymap');
  FContentTypes.AddOrSetValue('.ppm', 'image/x-portable-pixmap');
  FContentTypes.AddOrSetValue('.rgb', 'image/x-rgb');
  FContentTypes.AddOrSetValue('.tga', 'image/x-tga');
  FContentTypes.AddOrSetValue('.xbm', 'image/x-xbitmap');
  FContentTypes.AddOrSetValue('.xpm', 'image/x-xpixmap');
  FContentTypes.AddOrSetValue('.xwd', 'image/x-xwindowdump');
  FContentTypes.AddOrSetValue('.eml', 'message/rfc822');
  FContentTypes.AddOrSetValue('.mime', 'message/rfc822');
  FContentTypes.AddOrSetValue('.igs', 'model/iges');
  FContentTypes.AddOrSetValue('.iges', 'model/iges');
  FContentTypes.AddOrSetValue('.msh', 'model/mesh');
  FContentTypes.AddOrSetValue('.mesh', 'model/mesh');
  FContentTypes.AddOrSetValue('.silo', 'model/mesh');
  FContentTypes.AddOrSetValue('.dae', 'model/vnd.collada+xml');
  FContentTypes.AddOrSetValue('.dwf', 'model/vnd.dwf');
  FContentTypes.AddOrSetValue('.gdl', 'model/vnd.gdl');
  FContentTypes.AddOrSetValue('.gtw', 'model/vnd.gtw');
  FContentTypes.AddOrSetValue('.mts', 'model/vnd.mts');
  FContentTypes.AddOrSetValue('.vtu', 'model/vnd.vtu');
  FContentTypes.AddOrSetValue('.wrl', 'model/vrml');
  FContentTypes.AddOrSetValue('.vrml', 'model/vrml');
  FContentTypes.AddOrSetValue('.x3db', 'model/x3d+binary');
  FContentTypes.AddOrSetValue('.x3dbz', 'model/x3d+binary');
  FContentTypes.AddOrSetValue('.x3dv', 'model/x3d+vrml');
  FContentTypes.AddOrSetValue('.x3dvz', 'model/x3d+vrml');
  FContentTypes.AddOrSetValue('.x3d', 'model/x3d+xml');
  FContentTypes.AddOrSetValue('.x3dz', 'model/x3d+xml');
  FContentTypes.AddOrSetValue('.appcache', 'text/cache-manifest');
  FContentTypes.AddOrSetValue('.manifest', 'text/cache-manifest');
  FContentTypes.AddOrSetValue('.ics', 'text/calendar');
  FContentTypes.AddOrSetValue('.ifb', 'text/calendar');
  FContentTypes.AddOrSetValue('.coffee', 'text/coffeescript');
  FContentTypes.AddOrSetValue('.css', 'text/css');
  FContentTypes.AddOrSetValue('.csv', 'text/csv');
  FContentTypes.AddOrSetValue('.hjson', 'text/hjson');
  FContentTypes.AddOrSetValue('.html', 'text/html');
  FContentTypes.AddOrSetValue('.htm', 'text/html');
  FContentTypes.AddOrSetValue('.jade', 'text/jade');
  FContentTypes.AddOrSetValue('.jsx', 'text/jsx');
  FContentTypes.AddOrSetValue('.less', 'text/less');
  FContentTypes.AddOrSetValue('.n3', 'text/n3');
  FContentTypes.AddOrSetValue('.txt', 'text/plain');
  FContentTypes.AddOrSetValue('.text', 'text/plain');
  FContentTypes.AddOrSetValue('.conf', 'text/plain');
  FContentTypes.AddOrSetValue('.def', 'text/plain');
  FContentTypes.AddOrSetValue('.list', 'text/plain');
  FContentTypes.AddOrSetValue('.log', 'text/plain');
  FContentTypes.AddOrSetValue('.in', 'text/plain');
  FContentTypes.AddOrSetValue('.ini', 'text/plain');
  FContentTypes.AddOrSetValue('.dsc', 'text/prs.lines.tag');
  FContentTypes.AddOrSetValue('.rtx', 'text/richtext');
  FContentTypes.AddOrSetValue('.sgml', 'text/sgml');
  FContentTypes.AddOrSetValue('.sgm', 'text/sgml');
  FContentTypes.AddOrSetValue('.stylus', 'text/stylus');
  FContentTypes.AddOrSetValue('.styl', 'text/stylus');
  FContentTypes.AddOrSetValue('.tsv', 'text/tab-separated-values');
  FContentTypes.AddOrSetValue('.t', 'text/troff');
  FContentTypes.AddOrSetValue('.tr', 'text/troff');
  FContentTypes.AddOrSetValue('.roff', 'text/troff');
  FContentTypes.AddOrSetValue('.man', 'text/troff');
  FContentTypes.AddOrSetValue('.me', 'text/troff');
  FContentTypes.AddOrSetValue('.ms', 'text/troff');
  FContentTypes.AddOrSetValue('.ttl', 'text/turtle');
  FContentTypes.AddOrSetValue('.uri', 'text/uri-list');
  FContentTypes.AddOrSetValue('.uris', 'text/uri-list');
  FContentTypes.AddOrSetValue('.urls', 'text/uri-list');
  FContentTypes.AddOrSetValue('.vcard', 'text/vcard');
  FContentTypes.AddOrSetValue('.curl', 'text/vnd.curl');
  FContentTypes.AddOrSetValue('.dcurl', 'text/vnd.curl.dcurl');
  FContentTypes.AddOrSetValue('.mcurl', 'text/vnd.curl.mcurl');
  FContentTypes.AddOrSetValue('.scurl', 'text/vnd.curl.scurl');
  FContentTypes.AddOrSetValue('.sub', 'text/vnd.dvb.subtitle');
  FContentTypes.AddOrSetValue('.fly', 'text/vnd.fly');
  FContentTypes.AddOrSetValue('.flx', 'text/vnd.fmi.flexstor');
  FContentTypes.AddOrSetValue('.gv', 'text/vnd.graphviz');
  FContentTypes.AddOrSetValue('.3dml', 'text/vnd.in3d.3dml');
  FContentTypes.AddOrSetValue('.spot', 'text/vnd.in3d.spot');
  FContentTypes.AddOrSetValue('.jad', 'text/vnd.sun.j2me.app-descriptor');
  FContentTypes.AddOrSetValue('.wml', 'text/vnd.wap.wml');
  FContentTypes.AddOrSetValue('.wmls', 'text/vnd.wap.wmlscript');
  FContentTypes.AddOrSetValue('.vtt', 'text/vtt');
  FContentTypes.AddOrSetValue('.s', 'text/x-asm');
  FContentTypes.AddOrSetValue('.asm', 'text/x-asm');
  FContentTypes.AddOrSetValue('.c', 'text/x-c');
  FContentTypes.AddOrSetValue('.cc', 'text/x-c');
  FContentTypes.AddOrSetValue('.cxx', 'text/x-c');
  FContentTypes.AddOrSetValue('.cpp', 'text/x-c');
  FContentTypes.AddOrSetValue('.h', 'text/x-c');
  FContentTypes.AddOrSetValue('.hh', 'text/x-c');
  FContentTypes.AddOrSetValue('.dic', 'text/x-c');
  FContentTypes.AddOrSetValue('.htc', 'text/x-component');
  FContentTypes.AddOrSetValue('.f', 'text/x-fortran');
  FContentTypes.AddOrSetValue('.for', 'text/x-fortran');
  FContentTypes.AddOrSetValue('.f77', 'text/x-fortran');
  FContentTypes.AddOrSetValue('.f90', 'text/x-fortran');
  FContentTypes.AddOrSetValue('.hbs', 'text/x-handlebars-template');
  FContentTypes.AddOrSetValue('.java', 'text/x-java-source');
  FContentTypes.AddOrSetValue('.lua', 'text/x-lua');
  FContentTypes.AddOrSetValue('.markdown', 'text/x-markdown');
  FContentTypes.AddOrSetValue('.md', 'text/x-markdown');
  FContentTypes.AddOrSetValue('.mkd', 'text/x-markdown');
  FContentTypes.AddOrSetValue('.nfo', 'text/x-nfo');
  FContentTypes.AddOrSetValue('.opml', 'text/x-opml');
  FContentTypes.AddOrSetValue('.p', 'text/x-pascal');
  FContentTypes.AddOrSetValue('.pas', 'text/x-pascal');
  FContentTypes.AddOrSetValue('.sass', 'text/x-sass');
  FContentTypes.AddOrSetValue('.scss', 'text/x-scss');
  FContentTypes.AddOrSetValue('.etx', 'text/x-setext');
  FContentTypes.AddOrSetValue('.sfv', 'text/x-sfv');
  FContentTypes.AddOrSetValue('.uu', 'text/x-uuencode');
  FContentTypes.AddOrSetValue('.vcs', 'text/x-vcalendar');
  FContentTypes.AddOrSetValue('.vcf', 'text/x-vcard');
  FContentTypes.AddOrSetValue('.yaml', 'text/yaml');
  FContentTypes.AddOrSetValue('.yml', 'text/yaml');
  FContentTypes.AddOrSetValue('.3gp', 'video/3gpp');
  FContentTypes.AddOrSetValue('.3g2', 'video/3gpp2');
  FContentTypes.AddOrSetValue('.h261', 'video/h261');
  FContentTypes.AddOrSetValue('.h263', 'video/h263');
  FContentTypes.AddOrSetValue('.h264', 'video/h264');
  FContentTypes.AddOrSetValue('.jpgv', 'video/jpeg');
  FContentTypes.AddOrSetValue('.jpm', 'video/jpm');
  FContentTypes.AddOrSetValue('.jpgm', 'video/jpm');
  FContentTypes.AddOrSetValue('.mj2', 'video/mj2');
  FContentTypes.AddOrSetValue('.mjp2', 'video/mj2');
  FContentTypes.AddOrSetValue('.ts', 'video/mp2t');
  FContentTypes.AddOrSetValue('.mp4', 'video/mp4');
  FContentTypes.AddOrSetValue('.mp4v', 'video/mp4');
  FContentTypes.AddOrSetValue('.mpg4', 'video/mp4');
  FContentTypes.AddOrSetValue('.mpeg', 'video/mpeg');
  FContentTypes.AddOrSetValue('.mpg', 'video/mpeg');
  FContentTypes.AddOrSetValue('.mpe', 'video/mpeg');
  FContentTypes.AddOrSetValue('.m1v', 'video/mpeg');
  FContentTypes.AddOrSetValue('.m2v', 'video/mpeg');
  FContentTypes.AddOrSetValue('.ogv', 'video/ogg');
  FContentTypes.AddOrSetValue('.qt', 'video/quicktime');
  FContentTypes.AddOrSetValue('.mov', 'video/quicktime');
  FContentTypes.AddOrSetValue('.uvh', 'video/vnd.dece.hd');
  FContentTypes.AddOrSetValue('.uvvh', 'video/vnd.dece.hd');
  FContentTypes.AddOrSetValue('.uvm', 'video/vnd.dece.mobile');
  FContentTypes.AddOrSetValue('.uvvm', 'video/vnd.dece.mobile');
  FContentTypes.AddOrSetValue('.uvp', 'video/vnd.dece.pd');
  FContentTypes.AddOrSetValue('.uvvp', 'video/vnd.dece.pd');
  FContentTypes.AddOrSetValue('.uvs', 'video/vnd.dece.sd');
  FContentTypes.AddOrSetValue('.uvvs', 'video/vnd.dece.sd');
  FContentTypes.AddOrSetValue('.uvv', 'video/vnd.dece.video');
  FContentTypes.AddOrSetValue('.uvvv', 'video/vnd.dece.video');
  FContentTypes.AddOrSetValue('.dvb', 'video/vnd.dvb.file');
  FContentTypes.AddOrSetValue('.fvt', 'video/vnd.fvt');
  FContentTypes.AddOrSetValue('.mxu', 'video/vnd.mpegurl');
  FContentTypes.AddOrSetValue('.m4u', 'video/vnd.mpegurl');
  FContentTypes.AddOrSetValue('.pyv', 'video/vnd.ms-playready.media.pyv');
  FContentTypes.AddOrSetValue('.uvu', 'video/vnd.uvvu.mp4');
  FContentTypes.AddOrSetValue('.uvvu', 'video/vnd.uvvu.mp4');
  FContentTypes.AddOrSetValue('.viv', 'video/vnd.vivo');
  FContentTypes.AddOrSetValue('.webm', 'video/webm');
  FContentTypes.AddOrSetValue('.f4v', 'video/x-f4v');
  FContentTypes.AddOrSetValue('.fli', 'video/x-fli');
  FContentTypes.AddOrSetValue('.flv', 'video/x-flv');
  FContentTypes.AddOrSetValue('.m4v', 'video/x-m4v');
  FContentTypes.AddOrSetValue('.mkv', 'video/x-matroska');
  FContentTypes.AddOrSetValue('.mk3d', 'video/x-matroska');
  FContentTypes.AddOrSetValue('.mks', 'video/x-matroska');
  FContentTypes.AddOrSetValue('.mng', 'video/x-mng');
  FContentTypes.AddOrSetValue('.asf', 'video/x-ms-asf');
  FContentTypes.AddOrSetValue('.asx', 'video/x-ms-asf');
  FContentTypes.AddOrSetValue('.vob', 'video/x-ms-vob');
  FContentTypes.AddOrSetValue('.wm', 'video/x-ms-wm');
  FContentTypes.AddOrSetValue('.wmv', 'video/x-ms-wmv');
  FContentTypes.AddOrSetValue('.wmx', 'video/x-ms-wmx');
  FContentTypes.AddOrSetValue('.wvx', 'video/x-ms-wvx');
  FContentTypes.AddOrSetValue('.avi', 'video/x-msvideo');
  FContentTypes.AddOrSetValue('.movie', 'video/x-sgi-movie');
  FContentTypes.AddOrSetValue('.smv', 'video/x-smv');
  FContentTypes.AddOrSetValue('.ice', 'x-conference/x-cooltalk');
end;

procedure TStaticModule.AddApplicationContentTypes;
begin
  FContentTypes.AddOrSetValue('.ez', 'application/andrew-inset');
  FContentTypes.AddOrSetValue('.aw', 'application/applixware');
  FContentTypes.AddOrSetValue('.atom', 'application/atom+xml');
  FContentTypes.AddOrSetValue('.atomcat', 'application/atomcat+xml');
  FContentTypes.AddOrSetValue('.atomsvc', 'application/atomsvc+xml');
  FContentTypes.AddOrSetValue('.ccxml', 'application/ccxml+xml');
  FContentTypes.AddOrSetValue('.cdmia', 'application/cdmi-capability');
  FContentTypes.AddOrSetValue('.cdmic', 'application/cdmi-container');
  FContentTypes.AddOrSetValue('.cdmid', 'application/cdmi-domain');
  FContentTypes.AddOrSetValue('.cdmio', 'application/cdmi-object');
  FContentTypes.AddOrSetValue('.cdmiq', 'application/cdmi-queue');
  FContentTypes.AddOrSetValue('.cu', 'application/cu-seeme');
  FContentTypes.AddOrSetValue('.mdp', 'application/dash+xml');
  FContentTypes.AddOrSetValue('.davmount', 'application/davmount+xml');
  FContentTypes.AddOrSetValue('.dbk', 'application/docbook+xml');
  FContentTypes.AddOrSetValue('.dssc', 'application/dssc+der');
  FContentTypes.AddOrSetValue('.xdssc', 'application/dssc+xml');
  FContentTypes.AddOrSetValue('.ecma', 'application/ecmascript');
  FContentTypes.AddOrSetValue('.emma', 'application/emma+xml');
  FContentTypes.AddOrSetValue('.epub', 'application/epub+zip');
  FContentTypes.AddOrSetValue('.exi', 'application/exi');
  FContentTypes.AddOrSetValue('.pfr', 'application/font-tdpfr');
  FContentTypes.AddOrSetValue('.woff', 'application/font-woff');
  FContentTypes.AddOrSetValue('.woff2', 'application/font-woff2');
  FContentTypes.AddOrSetValue('.gml', 'application/gml+xml');
  FContentTypes.AddOrSetValue('.gpx', 'application/gpx+xml');
  FContentTypes.AddOrSetValue('.gxf', 'application/gxf');
  FContentTypes.AddOrSetValue('.stk', 'application/hyperstudio');
  FContentTypes.AddOrSetValue('.ink', 'application/inkml+xml');
  FContentTypes.AddOrSetValue('.inkml', 'application/inkml+xml');
  FContentTypes.AddOrSetValue('.ipfix', 'application/ipfix');
  FContentTypes.AddOrSetValue('.jar', 'application/java-archive');
  FContentTypes.AddOrSetValue('.ser', 'application/java-serialized-object');
  FContentTypes.AddOrSetValue('.class', 'application/java-vm');
  FContentTypes.AddOrSetValue('.js', 'application/javascript');
  FContentTypes.AddOrSetValue('.json', 'application/json');
  FContentTypes.AddOrSetValue('.map', 'application/json');
  FContentTypes.AddOrSetValue('.json5', 'application/json5');
  FContentTypes.AddOrSetValue('.jsonml', 'application/jsonml+json');
  FContentTypes.AddOrSetValue('.lostxml', 'application/lost+xml');
  FContentTypes.AddOrSetValue('.hqx', 'application/mac-binhex40');
  FContentTypes.AddOrSetValue('.cpt', 'application/mac-compactpro');
  FContentTypes.AddOrSetValue('.mads', 'application/mads+xml');
  FContentTypes.AddOrSetValue('.mrc', 'application/marc');
  FContentTypes.AddOrSetValue('.mrcx', 'application/marcxml+xml');
  FContentTypes.AddOrSetValue('.ma', 'application/mathematica');
  FContentTypes.AddOrSetValue('.nb', 'application/mathematica');
  FContentTypes.AddOrSetValue('.mb', 'application/mathematica');
  FContentTypes.AddOrSetValue('.mathml', 'application/mathml+xml');
  FContentTypes.AddOrSetValue('.mbox', 'application/mbox');
  FContentTypes.AddOrSetValue('.mscml', 'application/mediaservercontrol+xml');
  FContentTypes.AddOrSetValue('.metalink', 'application/metalink+xml');
  FContentTypes.AddOrSetValue('.meta4', 'application/metalink4+xml');
  FContentTypes.AddOrSetValue('.mets', 'application/mets+xml');
  FContentTypes.AddOrSetValue('.mods', 'application/mods+xml');
  FContentTypes.AddOrSetValue('.m21', 'application/mp21');
  FContentTypes.AddOrSetValue('.mp21', 'application/mp21');
  FContentTypes.AddOrSetValue('.mp4s', 'application/mp4');
  FContentTypes.AddOrSetValue('.m4p', 'application/mp4');
  FContentTypes.AddOrSetValue('.doc', 'application/msword');
  FContentTypes.AddOrSetValue('.dot', 'application/msword');
  FContentTypes.AddOrSetValue('.mxf', 'application/mxf');
  FContentTypes.AddOrSetValue('.bin', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.dms', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.lrf', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.mar', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.so', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.dist', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.distz', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.pkg', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.bpk', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.dump', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.elc', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.deploy', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.buffer', 'application/octet-stream');
  FContentTypes.AddOrSetValue('.oda', 'application/oda');
  FContentTypes.AddOrSetValue('.opf', 'application/oebps-package+xml');
  FContentTypes.AddOrSetValue('.ogx', 'application/ogg');
  FContentTypes.AddOrSetValue('.omdoc', 'application/omdoc+xml');
  FContentTypes.AddOrSetValue('.onetoc', 'application/onenote');
  FContentTypes.AddOrSetValue('.onetoc2', 'application/onenote');
  FContentTypes.AddOrSetValue('.onetmp', 'application/onenote');
  FContentTypes.AddOrSetValue('.onepkg', 'application/onenote');
  FContentTypes.AddOrSetValue('.oxps', 'application/oxps');
  FContentTypes.AddOrSetValue('.xer', 'application/patch-ops-error+xml');
  FContentTypes.AddOrSetValue('.pdf', 'application/pdf');
  FContentTypes.AddOrSetValue('.pgp', 'application/pgp-encrypted');
  FContentTypes.AddOrSetValue('.asc', 'application/pgp-signature');
  FContentTypes.AddOrSetValue('.sig', 'application/pgp-signature');
  FContentTypes.AddOrSetValue('.prf', 'application/pics-rules');
  FContentTypes.AddOrSetValue('.p10', 'application/pkcs10');
  FContentTypes.AddOrSetValue('.p7m', 'application/pkcs7-mime');
  FContentTypes.AddOrSetValue('.p7c', 'application/pkcs7-mime');
  FContentTypes.AddOrSetValue('.p7s', 'application/pkcs7-signature');
  FContentTypes.AddOrSetValue('.p8', 'application/pkcs8');
  FContentTypes.AddOrSetValue('.ac', 'application/pkix-attr-cert');
  FContentTypes.AddOrSetValue('.cer', 'application/pkix-cert');
  FContentTypes.AddOrSetValue('.crl', 'application/pkix-crl');
  FContentTypes.AddOrSetValue('.pkipath', 'application/pkix-pkipath');
  FContentTypes.AddOrSetValue('.pki', 'application/pkixcmp');
  FContentTypes.AddOrSetValue('.pls', 'application/pls+xml');
  FContentTypes.AddOrSetValue('.ai', 'application/postscript');
  FContentTypes.AddOrSetValue('.eps', 'application/postscript');
  FContentTypes.AddOrSetValue('.ps', 'application/postscript');
  FContentTypes.AddOrSetValue('.cww', 'application/prs.cww');
  FContentTypes.AddOrSetValue('.pskcxml', 'application/pskc+xml');
  FContentTypes.AddOrSetValue('.rdf', 'application/rdf+xml');
  FContentTypes.AddOrSetValue('.rif', 'application/reginfo+xml');
  FContentTypes.AddOrSetValue('.rnc', 'application/relax-ng-compact-syntax');
  FContentTypes.AddOrSetValue('.rl', 'application/resource-lists+xml');
  FContentTypes.AddOrSetValue('.rld', 'application/resource-lists-diff+xml');
  FContentTypes.AddOrSetValue('.rs', 'application/rls-services+xml');
  FContentTypes.AddOrSetValue('.gbr', 'application/rpki-ghostbusters');
  FContentTypes.AddOrSetValue('.mft', 'application/rpki-manifest');
  FContentTypes.AddOrSetValue('.roa', 'application/rpki-roa');
  FContentTypes.AddOrSetValue('.rsd', 'application/rsd+xml');
  FContentTypes.AddOrSetValue('.rss', 'application/rss+xml');
  FContentTypes.AddOrSetValue('.rtf', 'application/rtf');
  FContentTypes.AddOrSetValue('.sbml', 'application/sbml+xml');
  FContentTypes.AddOrSetValue('.scq', 'application/scvp-cv-request');
  FContentTypes.AddOrSetValue('.scs', 'application/scvp-cv-response');
  FContentTypes.AddOrSetValue('.spq', 'application/scvp-vp-request');
  FContentTypes.AddOrSetValue('.spp', 'application/scvp-vp-response');
  FContentTypes.AddOrSetValue('.sdp', 'application/sdp');
  FContentTypes.AddOrSetValue('.setpay', 'application/set-payment-initiation');
  FContentTypes.AddOrSetValue('.setreg', 'application/set-registration-initiation');
  FContentTypes.AddOrSetValue('.shf', 'application/shf+xml');
  FContentTypes.AddOrSetValue('.smi', 'application/smil+xml');
  FContentTypes.AddOrSetValue('.smil', 'application/smil+xml');
  FContentTypes.AddOrSetValue('.rq', 'application/sparql-query');
  FContentTypes.AddOrSetValue('.srx', 'application/sparql-results+xml');
  FContentTypes.AddOrSetValue('.gram', 'application/srgs');
  FContentTypes.AddOrSetValue('.grxml', 'application/srgs+xml');
  FContentTypes.AddOrSetValue('.sru', 'application/sru+xml');
  FContentTypes.AddOrSetValue('.ssdl', 'application/ssdl+xml');
  FContentTypes.AddOrSetValue('.ssml', 'application/ssml+xml');
  FContentTypes.AddOrSetValue('.tei', 'application/tei+xml');
  FContentTypes.AddOrSetValue('.teicorpus', 'application/tei+xml');
  FContentTypes.AddOrSetValue('.tfi', 'application/thraud+xml');
  FContentTypes.AddOrSetValue('.tsd', 'application/timestamped-data');
  FContentTypes.AddOrSetValue('.plb', 'application/vnd.3gpp.pic-bw-large');
  FContentTypes.AddOrSetValue('.psb', 'application/vnd.3gpp.pic-bw-small');
  FContentTypes.AddOrSetValue('.pvb', 'application/vnd.3gpp.pic-bw-var');
  FContentTypes.AddOrSetValue('.tcap', 'application/vnd.3gpp2.tcap');
  FContentTypes.AddOrSetValue('.pwn', 'application/vnd.3m.post-it-notes');
  FContentTypes.AddOrSetValue('.aso', 'application/vnd.accpac.simply.aso');
  FContentTypes.AddOrSetValue('.imp', 'application/vnd.accpac.simply.imp');
  FContentTypes.AddOrSetValue('.acu', 'application/vnd.acucobol');
  FContentTypes.AddOrSetValue('.atc', 'application/vnd.acucorp');
  FContentTypes.AddOrSetValue('.acutc', 'application/vnd.acucorp');
  FContentTypes.AddOrSetValue('.air', 'application/vnd.adobe.air-application-installer-package+zip');
  FContentTypes.AddOrSetValue('.fcdt', 'application/vnd.adobe.formscentral.fcdt');
  FContentTypes.AddOrSetValue('.fxp', 'application/vnd.adobe.fxp');
  FContentTypes.AddOrSetValue('.fxpl', 'application/vnd.adobe.fxp');
  FContentTypes.AddOrSetValue('.xdp', 'application/vnd.adobe.xdp+xml');
  FContentTypes.AddOrSetValue('.xfdf', 'application/vnd.adobe.xfdf');
  FContentTypes.AddOrSetValue('.ahead', 'application/vnd.ahead.space');
  FContentTypes.AddOrSetValue('.azf', 'application/vnd.airzip.filesecure.azf');
  FContentTypes.AddOrSetValue('.azs', 'application/vnd.airzip.filesecure.azs');
  FContentTypes.AddOrSetValue('.azw', 'application/vnd.amazon.ebook');
  FContentTypes.AddOrSetValue('.acc', 'application/vnd.americandynamics.acc');
  FContentTypes.AddOrSetValue('.ami', 'application/vnd.amiga.ami');
  FContentTypes.AddOrSetValue('.apk', 'application/vnd.android.package-archive');
  FContentTypes.AddOrSetValue('.cii', 'application/vnd.anser-web-certificate-issue-initiation');
  FContentTypes.AddOrSetValue('.fti', 'application/vnd.anser-web-funds-transfer-initiation');
  FContentTypes.AddOrSetValue('.atx', 'application/vnd.antix.game-component');
  FContentTypes.AddOrSetValue('.mpkg', 'application/vnd.apple.installer+xml');
  FContentTypes.AddOrSetValue('.m3u8', 'application/vnd.apple.mpegurl');
  FContentTypes.AddOrSetValue('.swi', 'application/vnd.aristanetworks.swi');
  FContentTypes.AddOrSetValue('.iota', 'application/vnd.astraea-software.iota');
  FContentTypes.AddOrSetValue('.aep', 'application/vnd.audiograph');
  FContentTypes.AddOrSetValue('.mpm', 'application/vnd.blueice.multipass');
  FContentTypes.AddOrSetValue('.bmi', 'application/vnd.bmi');
  FContentTypes.AddOrSetValue('.rep', 'application/vnd.businessobjects');
  FContentTypes.AddOrSetValue('.cdxml', 'application/vnd.chemdraw+xml');
  FContentTypes.AddOrSetValue('.mmd', 'application/vnd.chipnuts.karaoke-mmd');
  FContentTypes.AddOrSetValue('.cdy', 'application/vnd.cinderella');
  FContentTypes.AddOrSetValue('.cla', 'application/vnd.claymore');
  FContentTypes.AddOrSetValue('.rp9', 'application/vnd.cloanto.rp9');
  FContentTypes.AddOrSetValue('.c4g', 'application/vnd.clonk.c4group');
  FContentTypes.AddOrSetValue('.c4d', 'application/vnd.clonk.c4group');
  FContentTypes.AddOrSetValue('.c4f', 'application/vnd.clonk.c4group');
  FContentTypes.AddOrSetValue('.c4p', 'application/vnd.clonk.c4group');
  FContentTypes.AddOrSetValue('.c4u', 'application/vnd.clonk.c4group');
  FContentTypes.AddOrSetValue('.c11amc', 'application/vnd.cluetrust.cartomobile-config');
  FContentTypes.AddOrSetValue('.c11amz', 'application/vnd.cluetrust.cartomobile-config-pkg');
  FContentTypes.AddOrSetValue('.csp', 'application/vnd.commonspace');
  FContentTypes.AddOrSetValue('.cdbcmsg', 'application/vnd.contact.cmsg');
  FContentTypes.AddOrSetValue('.cmc', 'application/vnd.cosmocaller');
  FContentTypes.AddOrSetValue('.clkx', 'application/vnd.crick.clicker');
  FContentTypes.AddOrSetValue('.clkk', 'application/vnd.crick.clicker.keyboard');
  FContentTypes.AddOrSetValue('.clkp', 'application/vnd.crick.clicker.palette');
  FContentTypes.AddOrSetValue('.clkt', 'application/vnd.crick.clicker.template');
  FContentTypes.AddOrSetValue('.clkw', 'application/vnd.crick.clicker.wordbank');
  FContentTypes.AddOrSetValue('.wbs', 'application/vnd.criticaltools.wbs+xml');
  FContentTypes.AddOrSetValue('.pml', 'application/vnd.ctc-posml');
  FContentTypes.AddOrSetValue('.ppd', 'application/vnd.cups-ppd');
  FContentTypes.AddOrSetValue('.car', 'application/vnd.curl.car');
  FContentTypes.AddOrSetValue('.pcurl', 'application/vnd.curl.pcurl');
  FContentTypes.AddOrSetValue('.dart', 'application/vnd.dart');
  FContentTypes.AddOrSetValue('.rdz', 'application/vnd.data-vision.rdz');
  FContentTypes.AddOrSetValue('.uvf', 'application/vnd.dece.data');
  FContentTypes.AddOrSetValue('.uvvf', 'application/vnd.dece.data');
  FContentTypes.AddOrSetValue('.uvd', 'application/vnd.dece.data');
  FContentTypes.AddOrSetValue('.uvvd', 'application/vnd.dece.data');
  FContentTypes.AddOrSetValue('.uvt', 'application/vnd.dece.ttml+xml');
  FContentTypes.AddOrSetValue('.uvvt', 'application/vnd.dece.ttml+xml');
  FContentTypes.AddOrSetValue('.uvx', 'application/vnd.dece.unspecified');
  FContentTypes.AddOrSetValue('.uvvx', 'application/vnd.dece.unspecified');
  FContentTypes.AddOrSetValue('.uvz', 'application/vnd.dece.zip');
  FContentTypes.AddOrSetValue('.uvvz', 'application/vnd.dece.zip');
  FContentTypes.AddOrSetValue('.fe_launch', 'application/vnd.denovo.fcselayout-link');
  FContentTypes.AddOrSetValue('.dna', 'application/vnd.dna');
  FContentTypes.AddOrSetValue('.mlp', 'application/vnd.dolby.mlp');
  FContentTypes.AddOrSetValue('.dpg', 'application/vnd.dpgraph');
  FContentTypes.AddOrSetValue('.dfac', 'application/vnd.dreamfactory');
  FContentTypes.AddOrSetValue('.kpxx', 'application/vnd.ds-keypoint');
  FContentTypes.AddOrSetValue('.ait', 'application/vnd.dvb.ait');
  FContentTypes.AddOrSetValue('.svc', 'application/vnd.dvb.service');
  FContentTypes.AddOrSetValue('.geo', 'application/vnd.dynageo');
  FContentTypes.AddOrSetValue('.mag', 'application/vnd.ecowin.chart');
  FContentTypes.AddOrSetValue('.nml', 'application/vnd.enliven');
  FContentTypes.AddOrSetValue('.esf', 'application/vnd.epson.esf');
  FContentTypes.AddOrSetValue('.msf', 'application/vnd.epson.msf');
  FContentTypes.AddOrSetValue('.qam', 'application/vnd.epson.quickanime');
  FContentTypes.AddOrSetValue('.slt', 'application/vnd.epson.salt');
  FContentTypes.AddOrSetValue('.ssf', 'application/vnd.epson.ssf');
  FContentTypes.AddOrSetValue('.es3', 'application/vnd.eszigno3+xml');
  FContentTypes.AddOrSetValue('.et3', 'application/vnd.eszigno3+xml');
  FContentTypes.AddOrSetValue('.ez2', 'application/vnd.ezpix-album');
  FContentTypes.AddOrSetValue('.ez3', 'application/vnd.ezpix-package');
  FContentTypes.AddOrSetValue('.fdf', 'application/vnd.fdf');
  FContentTypes.AddOrSetValue('.mseed', 'application/vnd.fdsn.mseed');
  FContentTypes.AddOrSetValue('.seed', 'application/vnd.fdsn.seed');
  FContentTypes.AddOrSetValue('.dataless', 'application/vnd.fdsn.seed');
  FContentTypes.AddOrSetValue('.gph', 'application/vnd.flographit');
  FContentTypes.AddOrSetValue('.ftc', 'application/vnd.fluxtime.clip');
  FContentTypes.AddOrSetValue('.fm', 'application/vnd.framemaker');
  FContentTypes.AddOrSetValue('.frame', 'application/vnd.framemaker');
  FContentTypes.AddOrSetValue('.maker', 'application/vnd.framemaker');
  FContentTypes.AddOrSetValue('.book', 'application/vnd.framemaker');
  FContentTypes.AddOrSetValue('.fnc', 'application/vnd.frogans.fnc');
  FContentTypes.AddOrSetValue('.ltf', 'application/vnd.frogans.ltf');
  FContentTypes.AddOrSetValue('.fsc', 'application/vnd.fsc.weblaunch');
  FContentTypes.AddOrSetValue('.oas', 'application/vnd.fujitsu.oasys');
  FContentTypes.AddOrSetValue('.oa2', 'application/vnd.fujitsu.oasys2');
  FContentTypes.AddOrSetValue('.oa3', 'application/vnd.fujitsu.oasys3');
  FContentTypes.AddOrSetValue('.fg5', 'application/vnd.fujitsu.oasysgp');
  FContentTypes.AddOrSetValue('.bh2', 'application/vnd.fujitsu.oasysprs');
  FContentTypes.AddOrSetValue('.ddd', 'application/vnd.fujixerox.ddd');
  FContentTypes.AddOrSetValue('.xdw', 'application/vnd.fujixerox.docuworks');
  FContentTypes.AddOrSetValue('.xbd', 'application/vnd.fujixerox.docuworks.binder');
  FContentTypes.AddOrSetValue('.fzs', 'application/vnd.fuzzysheet');
  FContentTypes.AddOrSetValue('.txd', 'application/vnd.genomatix.tuxedo');
  FContentTypes.AddOrSetValue('.ggb', 'application/vnd.geogebra.file');
  FContentTypes.AddOrSetValue('.ggt', 'application/vnd.geogebra.tool');
  FContentTypes.AddOrSetValue('.gex', 'application/vnd.geometry-explorer');
  FContentTypes.AddOrSetValue('.gre', 'application/vnd.geometry-explorer');
  FContentTypes.AddOrSetValue('.gxt', 'application/vnd.geonext');
  FContentTypes.AddOrSetValue('.g2w', 'application/vnd.geoplan');
  FContentTypes.AddOrSetValue('.g3w', 'application/vnd.geospace');
  FContentTypes.AddOrSetValue('.gmx', 'application/vnd.gmx');
  FContentTypes.AddOrSetValue('.kml', 'application/vnd.google-earth.kml+xml');
  FContentTypes.AddOrSetValue('.kmz', 'application/vnd.google-earth.kmz');
  FContentTypes.AddOrSetValue('.gqf', 'application/vnd.grafeq');
  FContentTypes.AddOrSetValue('.gqs', 'application/vnd.grafeq');
  FContentTypes.AddOrSetValue('.gac', 'application/vnd.groove-account');
  FContentTypes.AddOrSetValue('.ghf', 'application/vnd.groove-help');
  FContentTypes.AddOrSetValue('.gim', 'application/vnd.groove-identity-message');
  FContentTypes.AddOrSetValue('.grv', 'application/vnd.groove-injector');
  FContentTypes.AddOrSetValue('.gtm', 'application/vnd.groove-tool-message');
  FContentTypes.AddOrSetValue('.tpl', 'application/vnd.groove-tool-template');
  FContentTypes.AddOrSetValue('.vcg', 'application/vnd.groove-vcard');
  FContentTypes.AddOrSetValue('.hal', 'application/vnd.hal+xml');
  FContentTypes.AddOrSetValue('.zmm', 'application/vnd.handheld-entertainment+xml');
  FContentTypes.AddOrSetValue('.hbci', 'application/vnd.hbci');
  FContentTypes.AddOrSetValue('.les', 'application/vnd.hhe.lesson-player');
  FContentTypes.AddOrSetValue('.hpgl', 'application/vnd.hp-hpgl');
  FContentTypes.AddOrSetValue('.hpid', 'application/vnd.hp-hpid');
  FContentTypes.AddOrSetValue('.hps', 'application/vnd.hp-hps');
  FContentTypes.AddOrSetValue('.jlt', 'application/vnd.hp-jlyt');
  FContentTypes.AddOrSetValue('.pcl', 'application/vnd.hp-pcl');
  FContentTypes.AddOrSetValue('.pclxl', 'application/vnd.hp-pclxl');
  FContentTypes.AddOrSetValue('.mpy', 'application/vnd.ibm.minipay');
  FContentTypes.AddOrSetValue('.afp', 'application/vnd.ibm.modcap');
  FContentTypes.AddOrSetValue('.listafp', 'application/vnd.ibm.modcap');
  FContentTypes.AddOrSetValue('.list3820', 'application/vnd.ibm.modcap');
  FContentTypes.AddOrSetValue('.irm', 'application/vnd.ibm.rights-management');
  FContentTypes.AddOrSetValue('.sc', 'application/vnd.ibm.secure-container');
  FContentTypes.AddOrSetValue('.icc', 'application/vnd.iccprofile');
  FContentTypes.AddOrSetValue('.icm', 'application/vnd.iccprofile');
  FContentTypes.AddOrSetValue('.igl', 'application/vnd.igloader');
  FContentTypes.AddOrSetValue('.ivp', 'application/vnd.immervision-ivp');
  FContentTypes.AddOrSetValue('.ivu', 'application/vnd.immervision-ivu');
  FContentTypes.AddOrSetValue('.igm', 'application/vnd.insors.igm');
  FContentTypes.AddOrSetValue('.xpw', 'application/vnd.intercon.formnet');
  FContentTypes.AddOrSetValue('.xpx', 'application/vnd.intercon.formnet');
  FContentTypes.AddOrSetValue('.i2g', 'application/vnd.intergeo');
  FContentTypes.AddOrSetValue('.qbo', 'application/vnd.intu.qbo');
  FContentTypes.AddOrSetValue('.qfx', 'application/vnd.intu.qfx');
  FContentTypes.AddOrSetValue('.rcprofile', 'application/vnd.ipunplugged.rcprofile');
  FContentTypes.AddOrSetValue('.irp', 'application/vnd.irepository.package+xml');
  FContentTypes.AddOrSetValue('.xpr', 'application/vnd.is-xpr');
  FContentTypes.AddOrSetValue('.fcs', 'application/vnd.isac.fcs');
  FContentTypes.AddOrSetValue('.jam', 'application/vnd.jam');
  FContentTypes.AddOrSetValue('.rms', 'application/vnd.jcp.javame.midlet-rms');
  FContentTypes.AddOrSetValue('.jisp', 'application/vnd.jisp');
  FContentTypes.AddOrSetValue('.joda', 'application/vnd.joost.joda-archive');
  FContentTypes.AddOrSetValue('.ktz', 'application/vnd.kahootz');
  FContentTypes.AddOrSetValue('.ktr', 'application/vnd.kahootz');
  FContentTypes.AddOrSetValue('.karbon', 'application/vnd.kde.karbon');
  FContentTypes.AddOrSetValue('.chrt', 'application/vnd.kde.kchart');
  FContentTypes.AddOrSetValue('.kfo', 'application/vnd.kde.kformula');
  FContentTypes.AddOrSetValue('.flw', 'application/vnd.kde.kivio');
  FContentTypes.AddOrSetValue('.kon', 'application/vnd.kde.kontour');
  FContentTypes.AddOrSetValue('.kpr', 'application/vnd.kde.kpresenter');
  FContentTypes.AddOrSetValue('.kpt', 'application/vnd.kde.kpresenter');
  FContentTypes.AddOrSetValue('.ksp', 'application/vnd.kde.kspread');
  FContentTypes.AddOrSetValue('.kwd', 'application/vnd.kde.kword');
  FContentTypes.AddOrSetValue('.kwt', 'application/vnd.kde.kword');
  FContentTypes.AddOrSetValue('.htke', 'application/vnd.kenameaapp');
  FContentTypes.AddOrSetValue('.kia', 'application/vnd.kidspiration');
  FContentTypes.AddOrSetValue('.kne', 'application/vnd.kinar');
  FContentTypes.AddOrSetValue('.knp', 'application/vnd.kinar');
  FContentTypes.AddOrSetValue('.skp', 'application/vnd.koan');
  FContentTypes.AddOrSetValue('.skd', 'application/vnd.koan');
  FContentTypes.AddOrSetValue('.skt', 'application/vnd.koan');
  FContentTypes.AddOrSetValue('.skm', 'application/vnd.koan');
  FContentTypes.AddOrSetValue('.sse', 'application/vnd.kodak-descriptor');
  FContentTypes.AddOrSetValue('.lasxml', 'application/vnd.las.las+xml');
  FContentTypes.AddOrSetValue('.lbd', 'application/vnd.llamagraphics.life-balance.desktop');
  FContentTypes.AddOrSetValue('.lbe', 'application/vnd.llamagraphics.life-balance.exchange+xml');
  FContentTypes.AddOrSetValue('.123', 'application/vnd.lotus-1-2-3');
  FContentTypes.AddOrSetValue('.apr', 'application/vnd.lotus-approach');
  FContentTypes.AddOrSetValue('.pre', 'application/vnd.lotus-freelance');
  FContentTypes.AddOrSetValue('.nsf', 'application/vnd.lotus-notes');
  FContentTypes.AddOrSetValue('.org', 'application/vnd.lotus-organizer');
  FContentTypes.AddOrSetValue('.scm', 'application/vnd.lotus-screencam');
  FContentTypes.AddOrSetValue('.lwp', 'application/vnd.lotus-wordpro');
  FContentTypes.AddOrSetValue('.portpkg', 'application/vnd.macports.portpkg');
  FContentTypes.AddOrSetValue('.mcd', 'application/vnd.mcd');
  FContentTypes.AddOrSetValue('.mc1', 'application/vnd.medcalcdata');
  FContentTypes.AddOrSetValue('.cdkey', 'application/vnd.mediastation.cdkey');
  FContentTypes.AddOrSetValue('.mwf', 'application/vnd.mfer');
  FContentTypes.AddOrSetValue('.mfm', 'application/vnd.mfmp');
  FContentTypes.AddOrSetValue('.flo', 'application/vnd.micrografx.flo');
  FContentTypes.AddOrSetValue('.igx', 'application/vnd.micrografx.igx');
  FContentTypes.AddOrSetValue('.mif', 'application/vnd.mif');
  FContentTypes.AddOrSetValue('.daf', 'application/vnd.mobius.daf');
  FContentTypes.AddOrSetValue('.dis', 'application/vnd.mobius.dis');
  FContentTypes.AddOrSetValue('.mbk', 'application/vnd.mobius.mbk');
  FContentTypes.AddOrSetValue('.mqy', 'application/vnd.mobius.mqy');
  FContentTypes.AddOrSetValue('.msl', 'application/vnd.mobius.msl');
  FContentTypes.AddOrSetValue('.plc', 'application/vnd.mobius.plc');
  FContentTypes.AddOrSetValue('.txf', 'application/vnd.mobius.txf');
  FContentTypes.AddOrSetValue('.mpn', 'application/vnd.mophun.application');
  FContentTypes.AddOrSetValue('.mpc', 'application/vnd.mophun.certificate');
  FContentTypes.AddOrSetValue('.xul', 'application/vnd.mozilla.xul+xml');
  FContentTypes.AddOrSetValue('.cil', 'application/vnd.ms-artgalry');
  FContentTypes.AddOrSetValue('.cab', 'application/vnd.ms-cab-compressed');
  FContentTypes.AddOrSetValue('.xls', 'application/vnd.ms-excel');
  FContentTypes.AddOrSetValue('.xlm', 'application/vnd.ms-excel');
  FContentTypes.AddOrSetValue('.xla', 'application/vnd.ms-excel');
  FContentTypes.AddOrSetValue('.xlc', 'application/vnd.ms-excel');
  FContentTypes.AddOrSetValue('.xlt', 'application/vnd.ms-excel');
  FContentTypes.AddOrSetValue('.xlw', 'application/vnd.ms-excel');
  FContentTypes.AddOrSetValue('.xlam', 'application/vnd.ms-excel.addin.macroenabled.12');
  FContentTypes.AddOrSetValue('.xlsb', 'application/vnd.ms-excel.sheet.binary.macroenabled.12');
  FContentTypes.AddOrSetValue('.xlsm', 'application/vnd.ms-excel.sheet.macroenabled.12');
  FContentTypes.AddOrSetValue('.xltm', 'application/vnd.ms-excel.template.macroenabled.12');
  FContentTypes.AddOrSetValue('.eot', 'application/vnd.ms-fontobject');
  FContentTypes.AddOrSetValue('.chm', 'application/vnd.ms-htmlhelp');
  FContentTypes.AddOrSetValue('.ims', 'application/vnd.ms-ims');
  FContentTypes.AddOrSetValue('.lrm', 'application/vnd.ms-lrm');
  FContentTypes.AddOrSetValue('.thmx', 'application/vnd.ms-officetheme');
  FContentTypes.AddOrSetValue('.cat', 'application/vnd.ms-pki.seccat');
  FContentTypes.AddOrSetValue('.stl', 'application/vnd.ms-pki.stl');
  FContentTypes.AddOrSetValue('.ppt', 'application/vnd.ms-powerpoint');
  FContentTypes.AddOrSetValue('.pps', 'application/vnd.ms-powerpoint');
  FContentTypes.AddOrSetValue('.pot', 'application/vnd.ms-powerpoint');
  FContentTypes.AddOrSetValue('.ppam', 'application/vnd.ms-powerpoint.addin.macroenabled.12');
  FContentTypes.AddOrSetValue('.pptm', 'application/vnd.ms-powerpoint.presentation.macroenabled.12');
  FContentTypes.AddOrSetValue('.sldm', 'application/vnd.ms-powerpoint.slide.macroenabled.12');
  FContentTypes.AddOrSetValue('.ppsm', 'application/vnd.ms-powerpoint.slideshow.macroenabled.12');
  FContentTypes.AddOrSetValue('.potm', 'application/vnd.ms-powerpoint.template.macroenabled.12');
  FContentTypes.AddOrSetValue('.mpp', 'application/vnd.ms-project');
  FContentTypes.AddOrSetValue('.mpt', 'application/vnd.ms-project');
  FContentTypes.AddOrSetValue('.docm', 'application/vnd.ms-word.document.macroenabled.12');
  FContentTypes.AddOrSetValue('.dotm', 'application/vnd.ms-word.template.macroenabled.12');
  FContentTypes.AddOrSetValue('.wps', 'application/vnd.ms-works');
  FContentTypes.AddOrSetValue('.wks', 'application/vnd.ms-works');
  FContentTypes.AddOrSetValue('.wcm', 'application/vnd.ms-works');
  FContentTypes.AddOrSetValue('.wdb', 'application/vnd.ms-works');
  FContentTypes.AddOrSetValue('.wpl', 'application/vnd.ms-wpl');
  FContentTypes.AddOrSetValue('.xps', 'application/vnd.ms-xpsdocument');
  FContentTypes.AddOrSetValue('.mseq', 'application/vnd.mseq');
  FContentTypes.AddOrSetValue('.mus', 'application/vnd.musician');
  FContentTypes.AddOrSetValue('.msty', 'application/vnd.muvee.style');
  FContentTypes.AddOrSetValue('.taglet', 'application/vnd.mynfc');
  FContentTypes.AddOrSetValue('.nlu', 'application/vnd.neurolanguage.nlu');
  FContentTypes.AddOrSetValue('.ntf', 'application/vnd.nitf');
  FContentTypes.AddOrSetValue('.nitf', 'application/vnd.nitf');
  FContentTypes.AddOrSetValue('.nnd', 'application/vnd.noblenet-directory');
  FContentTypes.AddOrSetValue('.nns', 'application/vnd.noblenet-sealer');
  FContentTypes.AddOrSetValue('.nnw', 'application/vnd.noblenet-web');
  FContentTypes.AddOrSetValue('.ngdat', 'application/vnd.nokia.n-gage.data');
  FContentTypes.AddOrSetValue('.rpst', 'application/vnd.nokia.radio-preset');
  FContentTypes.AddOrSetValue('.rpss', 'application/vnd.nokia.radio-presets');
  FContentTypes.AddOrSetValue('.edm', 'application/vnd.novadigm.edm');
  FContentTypes.AddOrSetValue('.edx', 'application/vnd.novadigm.edx');
  FContentTypes.AddOrSetValue('.ext', 'application/vnd.novadigm.ext');
  FContentTypes.AddOrSetValue('.odc', 'application/vnd.oasis.opendocument.chart');
  FContentTypes.AddOrSetValue('.otc', 'application/vnd.oasis.opendocument.chart-template');
  FContentTypes.AddOrSetValue('.odb', 'application/vnd.oasis.opendocument.database');
  FContentTypes.AddOrSetValue('.odf', 'application/vnd.oasis.opendocument.formula');
  FContentTypes.AddOrSetValue('.odft', 'application/vnd.oasis.opendocument.formula-template');
  FContentTypes.AddOrSetValue('.odg', 'application/vnd.oasis.opendocument.graphics');
  FContentTypes.AddOrSetValue('.otg', 'application/vnd.oasis.opendocument.graphics-template');
  FContentTypes.AddOrSetValue('.odi', 'application/vnd.oasis.opendocument.image');
  FContentTypes.AddOrSetValue('.oti', 'application/vnd.oasis.opendocument.image-template');
  FContentTypes.AddOrSetValue('.odp', 'application/vnd.oasis.opendocument.presentation');
  FContentTypes.AddOrSetValue('.otp', 'application/vnd.oasis.opendocument.presentation-template');
  FContentTypes.AddOrSetValue('.ods', 'application/vnd.oasis.opendocument.spreadsheet');
  FContentTypes.AddOrSetValue('.ots', 'application/vnd.oasis.opendocument.spreadsheet-template');
  FContentTypes.AddOrSetValue('.odt', 'application/vnd.oasis.opendocument.text');
  FContentTypes.AddOrSetValue('.odm', 'application/vnd.oasis.opendocument.text-master');
  FContentTypes.AddOrSetValue('.ott', 'application/vnd.oasis.opendocument.text-template');
  FContentTypes.AddOrSetValue('.oth', 'application/vnd.oasis.opendocument.text-web');
  FContentTypes.AddOrSetValue('.xo', 'application/vnd.olpc-sugar');
  FContentTypes.AddOrSetValue('.dd2', 'application/vnd.oma.dd2+xml');
  FContentTypes.AddOrSetValue('.oxt', 'application/vnd.openofficeorg.extension');
  FContentTypes.AddOrSetValue('.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation');
  FContentTypes.AddOrSetValue('.sldx', 'application/vnd.openxmlformats-officedocument.presentationml.slide');
  FContentTypes.AddOrSetValue('.ppsx', 'application/vnd.openxmlformats-officedocument.presentationml.slideshow');
  FContentTypes.AddOrSetValue('.potx', 'application/vnd.openxmlformats-officedocument.presentationml.template');
  FContentTypes.AddOrSetValue('.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  FContentTypes.AddOrSetValue('.xltx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.template');
  FContentTypes.AddOrSetValue('.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
  FContentTypes.AddOrSetValue('.dotx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template');
  FContentTypes.AddOrSetValue('.mgp', 'application/vnd.osgeo.mapguide.package');
  FContentTypes.AddOrSetValue('.dp', 'application/vnd.osgi.dp');
  FContentTypes.AddOrSetValue('.esa', 'application/vnd.osgi.subsystem');
  FContentTypes.AddOrSetValue('.pdb', 'application/vnd.palm');
  FContentTypes.AddOrSetValue('.pqa', 'application/vnd.palm');
  FContentTypes.AddOrSetValue('.oprc', 'application/vnd.palm');
  FContentTypes.AddOrSetValue('.paw', 'application/vnd.pawaafile');
  FContentTypes.AddOrSetValue('.str', 'application/vnd.pg.format');
  FContentTypes.AddOrSetValue('.ei6', 'application/vnd.pg.osasli');
  FContentTypes.AddOrSetValue('.efif', 'application/vnd.picsel');
  FContentTypes.AddOrSetValue('.wg', 'application/vnd.pmi.widget');
  FContentTypes.AddOrSetValue('.plf', 'application/vnd.pocketlearn');
  FContentTypes.AddOrSetValue('.pbd', 'application/vnd.powerbuilder6');
  FContentTypes.AddOrSetValue('.box', 'application/vnd.previewsystems.box');
  FContentTypes.AddOrSetValue('.mgz', 'application/vnd.proteus.magazine');
  FContentTypes.AddOrSetValue('.qps', 'application/vnd.publishare-delta-tree');
  FContentTypes.AddOrSetValue('.ptid', 'application/vnd.pvi.ptid1');
  FContentTypes.AddOrSetValue('.qxd', 'application/vnd.quark.quarkxpress');
  FContentTypes.AddOrSetValue('.qxt', 'application/vnd.quark.quarkxpress');
  FContentTypes.AddOrSetValue('.qwd', 'application/vnd.quark.quarkxpress');
  FContentTypes.AddOrSetValue('.qwt', 'application/vnd.quark.quarkxpress');
  FContentTypes.AddOrSetValue('.qxl', 'application/vnd.quark.quarkxpress');
  FContentTypes.AddOrSetValue('.qxb', 'application/vnd.quark.quarkxpress');
  FContentTypes.AddOrSetValue('.bed', 'application/vnd.realvnc.bed');
  FContentTypes.AddOrSetValue('.mxl', 'application/vnd.recordare.musicxml');
  FContentTypes.AddOrSetValue('.musicxml', 'application/vnd.recordare.musicxml+xml');
  FContentTypes.AddOrSetValue('.cryptonote', 'application/vnd.rig.cryptonote');
  FContentTypes.AddOrSetValue('.cod', 'application/vnd.rim.cod');
  FContentTypes.AddOrSetValue('.rm', 'application/vnd.rn-realmedia');
  FContentTypes.AddOrSetValue('.rmvb', 'application/vnd.rn-realmedia-vbr');
  FContentTypes.AddOrSetValue('.link66', 'application/vnd.route66.link66+xml');
  FContentTypes.AddOrSetValue('.st', 'application/vnd.sailingtracker.track');
  FContentTypes.AddOrSetValue('.see', 'application/vnd.seemail');
  FContentTypes.AddOrSetValue('.sema', 'application/vnd.sema');
  FContentTypes.AddOrSetValue('.semd', 'application/vnd.semd');
  FContentTypes.AddOrSetValue('.semf', 'application/vnd.semf');
  FContentTypes.AddOrSetValue('.ifm', 'application/vnd.shana.informed.formdata');
  FContentTypes.AddOrSetValue('.itp', 'application/vnd.shana.informed.formtemplate');
  FContentTypes.AddOrSetValue('.iif', 'application/vnd.shana.informed.interchange');
  FContentTypes.AddOrSetValue('.ipk', 'application/vnd.shana.informed.package');
  FContentTypes.AddOrSetValue('.twd', 'application/vnd.simtech-mindmapper');
  FContentTypes.AddOrSetValue('.twds', 'application/vnd.simtech-mindmapper');
  FContentTypes.AddOrSetValue('.mmf', 'application/vnd.smaf');
  FContentTypes.AddOrSetValue('.teacher', 'application/vnd.smart.teacher');
  FContentTypes.AddOrSetValue('.sdkm', 'application/vnd.solent.sdkm+xml');
  FContentTypes.AddOrSetValue('.sdkd', 'application/vnd.solent.sdkm+xml');
  FContentTypes.AddOrSetValue('.dxp', 'application/vnd.spotfire.dxp');
  FContentTypes.AddOrSetValue('.sfs', 'application/vnd.spotfire.sfs');
  FContentTypes.AddOrSetValue('.sdc', 'application/vnd.stardivision.calc');
  FContentTypes.AddOrSetValue('.sda', 'application/vnd.stardivision.draw');
  FContentTypes.AddOrSetValue('.sdd', 'application/vnd.stardivision.impress');
  FContentTypes.AddOrSetValue('.smf', 'application/vnd.stardivision.math');
  FContentTypes.AddOrSetValue('.sdw', 'application/vnd.stardivision.writer');
  FContentTypes.AddOrSetValue('.vor', 'application/vnd.stardivision.writer');
  FContentTypes.AddOrSetValue('.sgl', 'application/vnd.stardivision.writer-global');
  FContentTypes.AddOrSetValue('.smzip', 'application/vnd.stepmania.package');
  FContentTypes.AddOrSetValue('.sm', 'application/vnd.stepmania.stepchart');
  FContentTypes.AddOrSetValue('.sxc', 'application/vnd.sun.xml.calc');
  FContentTypes.AddOrSetValue('.stc', 'application/vnd.sun.xml.calc.template');
  FContentTypes.AddOrSetValue('.sxd', 'application/vnd.sun.xml.draw');
  FContentTypes.AddOrSetValue('.std', 'application/vnd.sun.xml.draw.template');
  FContentTypes.AddOrSetValue('.sxi', 'application/vnd.sun.xml.impress');
  FContentTypes.AddOrSetValue('.sti', 'application/vnd.sun.xml.impress.template');
  FContentTypes.AddOrSetValue('.sxm', 'application/vnd.sun.xml.math');
  FContentTypes.AddOrSetValue('.sxw', 'application/vnd.sun.xml.writer');
  FContentTypes.AddOrSetValue('.sxg', 'application/vnd.sun.xml.writer.global');
  FContentTypes.AddOrSetValue('.stw', 'application/vnd.sun.xml.writer.template');
  FContentTypes.AddOrSetValue('.sus', 'application/vnd.sus-calendar');
  FContentTypes.AddOrSetValue('.susp', 'application/vnd.sus-calendar');
  FContentTypes.AddOrSetValue('.svd', 'application/vnd.svd');
  FContentTypes.AddOrSetValue('.sis', 'application/vnd.symbian.install');
  FContentTypes.AddOrSetValue('.sisx', 'application/vnd.symbian.install');
  FContentTypes.AddOrSetValue('.xsm', 'application/vnd.syncml+xml');
  FContentTypes.AddOrSetValue('.bdm', 'application/vnd.syncml.dm+wbxml');
  FContentTypes.AddOrSetValue('.xdm', 'application/vnd.syncml.dm+xml');
  FContentTypes.AddOrSetValue('.tao', 'application/vnd.tao.intent-module-archive');
  FContentTypes.AddOrSetValue('.pcap', 'application/vnd.tcpdump.pcap');
  FContentTypes.AddOrSetValue('.cap', 'application/vnd.tcpdump.pcap');
  FContentTypes.AddOrSetValue('.dmp', 'application/vnd.tcpdump.pcap');
  FContentTypes.AddOrSetValue('.tmo', 'application/vnd.tmobile-livetv');
  FContentTypes.AddOrSetValue('.tpt', 'application/vnd.trid.tpt');
  FContentTypes.AddOrSetValue('.mxs', 'application/vnd.triscape.mxs');
  FContentTypes.AddOrSetValue('.tra', 'application/vnd.trueapp');
  FContentTypes.AddOrSetValue('.ufd', 'application/vnd.ufdl');
  FContentTypes.AddOrSetValue('.ufdl', 'application/vnd.ufdl');
  FContentTypes.AddOrSetValue('.utz', 'application/vnd.uiq.theme');
  FContentTypes.AddOrSetValue('.umj', 'application/vnd.umajin');
  FContentTypes.AddOrSetValue('.unityweb', 'application/vnd.unity');
  FContentTypes.AddOrSetValue('.uoml', 'application/vnd.uoml+xml');
  FContentTypes.AddOrSetValue('.vcx', 'application/vnd.vcx');
  FContentTypes.AddOrSetValue('.vsd', 'application/vnd.visio');
  FContentTypes.AddOrSetValue('.vst', 'application/vnd.visio');
  FContentTypes.AddOrSetValue('.vss', 'application/vnd.visio');
  FContentTypes.AddOrSetValue('.vsw', 'application/vnd.visio');
  FContentTypes.AddOrSetValue('.vis', 'application/vnd.visionary');
  FContentTypes.AddOrSetValue('.vsf', 'application/vnd.vsf');
  FContentTypes.AddOrSetValue('.wbxml', 'application/vnd.wap.wbxml');
  FContentTypes.AddOrSetValue('.wmlc', 'application/vnd.wap.wmlc');
  FContentTypes.AddOrSetValue('.wmlsc', 'application/vnd.wap.wmlscriptc');
  FContentTypes.AddOrSetValue('.wtb', 'application/vnd.webturbo');
  FContentTypes.AddOrSetValue('.nbp', 'application/vnd.wolfram.player');
  FContentTypes.AddOrSetValue('.wpd', 'application/vnd.wordperfect');
  FContentTypes.AddOrSetValue('.wqd', 'application/vnd.wqd');
  FContentTypes.AddOrSetValue('.stf', 'application/vnd.wt.stf');
  FContentTypes.AddOrSetValue('.xar', 'application/vnd.xara');
  FContentTypes.AddOrSetValue('.xfdl', 'application/vnd.xfdl');
  FContentTypes.AddOrSetValue('.hvd', 'application/vnd.yamaha.hv-dic');
  FContentTypes.AddOrSetValue('.hvs', 'application/vnd.yamaha.hv-script');
  FContentTypes.AddOrSetValue('.hvp', 'application/vnd.yamaha.hv-voice');
  FContentTypes.AddOrSetValue('.osf', 'application/vnd.yamaha.openscoreformat');
  FContentTypes.AddOrSetValue('.osfpvg', 'application/vnd.yamaha.openscoreformat.osfpvg+xml');
  FContentTypes.AddOrSetValue('.saf', 'application/vnd.yamaha.smaf-audio');
  FContentTypes.AddOrSetValue('.spf', 'application/vnd.yamaha.smaf-phrase');
  FContentTypes.AddOrSetValue('.cmp', 'application/vnd.yellowriver-custom-menu');
  FContentTypes.AddOrSetValue('.zir', 'application/vnd.zul');
  FContentTypes.AddOrSetValue('.zirz', 'application/vnd.zul');
  FContentTypes.AddOrSetValue('.zaz', 'application/vnd.zzazz.deck+xml');
  FContentTypes.AddOrSetValue('.vxml', 'application/voicexml+xml');
  FContentTypes.AddOrSetValue('.wgt', 'application/widget');
  FContentTypes.AddOrSetValue('.hlp', 'application/winhlp');
  FContentTypes.AddOrSetValue('.wsdl', 'application/wsdl+xml');
  FContentTypes.AddOrSetValue('.wspolicy', 'application/wspolicy+xml');
  FContentTypes.AddOrSetValue('.7z', 'application/x-7z-compressed');
  FContentTypes.AddOrSetValue('.abw', 'application/x-abiword');
  FContentTypes.AddOrSetValue('.ace', 'application/x-ace-compressed');
  FContentTypes.AddOrSetValue('.dmg', 'application/x-apple-diskimage');
  FContentTypes.AddOrSetValue('.aab', 'application/x-authorware-bin');
  FContentTypes.AddOrSetValue('.x32', 'application/x-authorware-bin');
  FContentTypes.AddOrSetValue('.u32', 'application/x-authorware-bin');
  FContentTypes.AddOrSetValue('.vox', 'application/x-authorware-bin');
  FContentTypes.AddOrSetValue('.aam', 'application/x-authorware-map');
  FContentTypes.AddOrSetValue('.aas', 'application/x-authorware-seg');
  FContentTypes.AddOrSetValue('.bcpio', 'application/x-bcpio');
  FContentTypes.AddOrSetValue('.torrent', 'application/x-bittorrent');
  FContentTypes.AddOrSetValue('.blb', 'application/x-blorb');
  FContentTypes.AddOrSetValue('.blorb', 'application/x-blorb');
  FContentTypes.AddOrSetValue('.bz', 'application/x-bzip');
  FContentTypes.AddOrSetValue('.bz2', 'application/x-bzip2');
  FContentTypes.AddOrSetValue('.boz', 'application/x-bzip2');
  FContentTypes.AddOrSetValue('.cbr', 'application/x-cbr');
  FContentTypes.AddOrSetValue('.cba', 'application/x-cbr');
  FContentTypes.AddOrSetValue('.cbt', 'application/x-cbr');
  FContentTypes.AddOrSetValue('.cbz', 'application/x-cbr');
  FContentTypes.AddOrSetValue('.cb7', 'application/x-cbr');
  FContentTypes.AddOrSetValue('.vcd', 'application/x-cdlink');
  FContentTypes.AddOrSetValue('.cfs', 'application/x-cfs-compressed');
  FContentTypes.AddOrSetValue('.chat', 'application/x-chat');
  FContentTypes.AddOrSetValue('.pgn', 'application/x-chess-pgn');
  FContentTypes.AddOrSetValue('.crx', 'application/x-chrome-extension');
  FContentTypes.AddOrSetValue('.nsc', 'application/x-conference');
  FContentTypes.AddOrSetValue('.cpio', 'application/x-cpio');
  FContentTypes.AddOrSetValue('.csh', 'application/x-csh');
  FContentTypes.AddOrSetValue('.deb', 'application/x-debian-package');
  FContentTypes.AddOrSetValue('.udeb', 'application/x-debian-package');
  FContentTypes.AddOrSetValue('.dgc', 'application/x-dgc-compressed');
  FContentTypes.AddOrSetValue('.dir', 'application/x-director');
  FContentTypes.AddOrSetValue('.dcr', 'application/x-director');
  FContentTypes.AddOrSetValue('.dxr', 'application/x-director');
  FContentTypes.AddOrSetValue('.cst', 'application/x-director');
  FContentTypes.AddOrSetValue('.cct', 'application/x-director');
  FContentTypes.AddOrSetValue('.cxt', 'application/x-director');
  FContentTypes.AddOrSetValue('.w3d', 'application/x-director');
  FContentTypes.AddOrSetValue('.fgd', 'application/x-director');
  FContentTypes.AddOrSetValue('.swa', 'application/x-director');
  FContentTypes.AddOrSetValue('.wad', 'application/x-doom');
  FContentTypes.AddOrSetValue('.ncx', 'application/x-dtbncx+xml');
  FContentTypes.AddOrSetValue('.dtb', 'application/x-dtbook+xml');
  FContentTypes.AddOrSetValue('.res', 'application/x-dtbresource+xml');
  FContentTypes.AddOrSetValue('.dvi', 'application/x-dvi');
  FContentTypes.AddOrSetValue('.evy', 'application/x-envoy');
  FContentTypes.AddOrSetValue('.eva', 'application/x-eva');
  FContentTypes.AddOrSetValue('.bdf', 'application/x-font-bdf');
  FContentTypes.AddOrSetValue('.gsf', 'application/x-font-ghostscript');
  FContentTypes.AddOrSetValue('.psf', 'application/x-font-linux-psf');
//  FContentTypes.AddOrSetValue('.otf', 'application/x-font-otf');
  FContentTypes.AddOrSetValue('.pcf', 'application/x-font-pcf');
  FContentTypes.AddOrSetValue('.snf', 'application/x-font-snf');
  FContentTypes.AddOrSetValue('.ttf', 'application/x-font-ttf');
  FContentTypes.AddOrSetValue('.ttc', 'application/x-font-ttf');
  FContentTypes.AddOrSetValue('.pfa', 'application/x-font-type1');
  FContentTypes.AddOrSetValue('.pfb', 'application/x-font-type1');
  FContentTypes.AddOrSetValue('.pfm', 'application/x-font-type1');
  FContentTypes.AddOrSetValue('.afm', 'application/x-font-type1');
  FContentTypes.AddOrSetValue('.arc', 'application/x-freearc');
  FContentTypes.AddOrSetValue('.spl', 'application/x-futuresplash');
  FContentTypes.AddOrSetValue('.gca', 'application/x-gca-compressed');
  FContentTypes.AddOrSetValue('.ulx', 'application/x-glulx');
  FContentTypes.AddOrSetValue('.gnumeric', 'application/x-gnumeric');
  FContentTypes.AddOrSetValue('.gramps', 'application/x-gramps-xml');
  FContentTypes.AddOrSetValue('.gtar', 'application/x-gtar');
  FContentTypes.AddOrSetValue('.hdf', 'application/x-hdf');
  FContentTypes.AddOrSetValue('.install', 'application/x-install-instructions');
  FContentTypes.AddOrSetValue('.iso', 'application/x-iso9660-image');
  FContentTypes.AddOrSetValue('.jnlp', 'application/x-java-jnlp-file');
  FContentTypes.AddOrSetValue('.latex', 'application/x-latex');
  FContentTypes.AddOrSetValue('.luac', 'application/x-lua-bytecode');
  FContentTypes.AddOrSetValue('.lzh', 'application/x-lzh-compressed');
  FContentTypes.AddOrSetValue('.lha', 'application/x-lzh-compressed');
  FContentTypes.AddOrSetValue('.mie', 'application/x-mie');
  FContentTypes.AddOrSetValue('.prc', 'application/x-mobipocket-ebook');
  FContentTypes.AddOrSetValue('.mobi', 'application/x-mobipocket-ebook');
  FContentTypes.AddOrSetValue('.application', 'application/x-ms-application');
  FContentTypes.AddOrSetValue('.lnk', 'application/x-ms-shortcut');
  FContentTypes.AddOrSetValue('.wmd', 'application/x-ms-wmd');
//  FContentTypes.AddOrSetValue('.wmz', 'application/x-ms-wmz');
  FContentTypes.AddOrSetValue('.xbap', 'application/x-ms-xbap');
  FContentTypes.AddOrSetValue('.mdb', 'application/x-msaccess');
  FContentTypes.AddOrSetValue('.obd', 'application/x-msbinder');
  FContentTypes.AddOrSetValue('.crd', 'application/x-mscardfile');
  FContentTypes.AddOrSetValue('.clp', 'application/x-msclip');
  FContentTypes.AddOrSetValue('.exe', 'application/x-msdownload');
  FContentTypes.AddOrSetValue('.dll', 'application/x-msdownload');
  FContentTypes.AddOrSetValue('.com', 'application/x-msdownload');
  FContentTypes.AddOrSetValue('.bat', 'application/x-msdownload');
  FContentTypes.AddOrSetValue('.msi', 'application/x-msdownload');
  FContentTypes.AddOrSetValue('.mvb', 'application/x-msmediaview');
  FContentTypes.AddOrSetValue('.m13', 'application/x-msmediaview');
  FContentTypes.AddOrSetValue('.m14', 'application/x-msmediaview');
  FContentTypes.AddOrSetValue('.wmf', 'application/x-msmetafile');
  FContentTypes.AddOrSetValue('.wmz', 'application/x-msmetafile');
  FContentTypes.AddOrSetValue('.emf', 'application/x-msmetafile');
  FContentTypes.AddOrSetValue('.emz', 'application/x-msmetafile');
  FContentTypes.AddOrSetValue('.mny', 'application/x-msmoney');
  FContentTypes.AddOrSetValue('.pub', 'application/x-mspublisher');
  FContentTypes.AddOrSetValue('.scd', 'application/x-msschedule');
  FContentTypes.AddOrSetValue('.trm', 'application/x-msterminal');
  FContentTypes.AddOrSetValue('.wri', 'application/x-mswrite');
  FContentTypes.AddOrSetValue('.nc', 'application/x-netcdf');
  FContentTypes.AddOrSetValue('.cdf', 'application/x-netcdf');
  FContentTypes.AddOrSetValue('.nzb', 'application/x-nzb');
  FContentTypes.AddOrSetValue('.p12', 'application/x-pkcs12');
  FContentTypes.AddOrSetValue('.pfx', 'application/x-pkcs12');
  FContentTypes.AddOrSetValue('.p7b', 'application/x-pkcs7-certificates');
  FContentTypes.AddOrSetValue('.spc', 'application/x-pkcs7-certificates');
  FContentTypes.AddOrSetValue('.p7r', 'application/x-pkcs7-certreqresp');
  FContentTypes.AddOrSetValue('.rar', 'application/x-rar-compressed');
  FContentTypes.AddOrSetValue('.ris', 'application/x-research-info-systems');
  FContentTypes.AddOrSetValue('.sh', 'application/x-sh');
  FContentTypes.AddOrSetValue('.shar', 'application/x-shar');
  FContentTypes.AddOrSetValue('.swf', 'application/x-shockwave-flash');
  FContentTypes.AddOrSetValue('.xap', 'application/x-silverlight-app');
  FContentTypes.AddOrSetValue('.sql', 'application/x-sql');
  FContentTypes.AddOrSetValue('.sit', 'application/x-stuffit');
  FContentTypes.AddOrSetValue('.sitx', 'application/x-stuffitx');
  FContentTypes.AddOrSetValue('.srt', 'application/x-subrip');
  FContentTypes.AddOrSetValue('.sv4cpio', 'application/x-sv4cpio');
  FContentTypes.AddOrSetValue('.sv4crc', 'application/x-sv4crc');
  FContentTypes.AddOrSetValue('.t3', 'application/x-t3vm-image');
  FContentTypes.AddOrSetValue('.gam', 'application/x-tads');
  FContentTypes.AddOrSetValue('.tar', 'application/x-tar');
  FContentTypes.AddOrSetValue('.tcl', 'application/x-tcl');
  FContentTypes.AddOrSetValue('.tex', 'application/x-tex');
  FContentTypes.AddOrSetValue('.tfm', 'application/x-tex-tfm');
  FContentTypes.AddOrSetValue('.texinfo', 'application/x-texinfo');
  FContentTypes.AddOrSetValue('.texi', 'application/x-texinfo');
  FContentTypes.AddOrSetValue('.obj', 'application/x-tgif');
  FContentTypes.AddOrSetValue('.ustar', 'application/x-ustar');
  FContentTypes.AddOrSetValue('.src', 'application/x-wais-source');
  FContentTypes.AddOrSetValue('.webapp', 'application/x-web-app-manifest+json');
  FContentTypes.AddOrSetValue('.der', 'application/x-x509-ca-cert');
  FContentTypes.AddOrSetValue('.crt', 'application/x-x509-ca-cert');
  FContentTypes.AddOrSetValue('.fig', 'application/x-xfig');
  FContentTypes.AddOrSetValue('.xlf', 'application/x-xliff+xml');
  FContentTypes.AddOrSetValue('.xpi', 'application/x-xpinstall');
  FContentTypes.AddOrSetValue('.xz', 'application/x-xz');
  FContentTypes.AddOrSetValue('.z1', 'application/x-zmachine');
  FContentTypes.AddOrSetValue('.z2', 'application/x-zmachine');
  FContentTypes.AddOrSetValue('.z3', 'application/x-zmachine');
  FContentTypes.AddOrSetValue('.z4', 'application/x-zmachine');
  FContentTypes.AddOrSetValue('.z5', 'application/x-zmachine');
  FContentTypes.AddOrSetValue('.z6', 'application/x-zmachine');
  FContentTypes.AddOrSetValue('.z7', 'application/x-zmachine');
  FContentTypes.AddOrSetValue('.z8', 'application/x-zmachine');
  FContentTypes.AddOrSetValue('.xaml', 'application/xaml+xml');
  FContentTypes.AddOrSetValue('.xdf', 'application/xcap-diff+xml');
  FContentTypes.AddOrSetValue('.xenc', 'application/xenc+xml');
  FContentTypes.AddOrSetValue('.xhtml', 'application/xhtml+xml');
  FContentTypes.AddOrSetValue('.xht', 'application/xhtml+xml');
  FContentTypes.AddOrSetValue('.xml', 'application/xml');
  FContentTypes.AddOrSetValue('.xsl', 'application/xml');
  FContentTypes.AddOrSetValue('.xsd', 'application/xml');
  FContentTypes.AddOrSetValue('.dtd', 'application/xml-dtd');
  FContentTypes.AddOrSetValue('.xop', 'application/xop+xml');
  FContentTypes.AddOrSetValue('.xpl', 'application/xproc+xml');
  FContentTypes.AddOrSetValue('.xslt', 'application/xslt+xml');
  FContentTypes.AddOrSetValue('.xspf', 'application/xspf+xml');
  FContentTypes.AddOrSetValue('.mxml', 'application/xv+xml');
  FContentTypes.AddOrSetValue('.xhvml', 'application/xv+xml');
  FContentTypes.AddOrSetValue('.xvml', 'application/xv+xml');
  FContentTypes.AddOrSetValue('.xvm', 'application/xv+xml');
  FContentTypes.AddOrSetValue('.yang', 'application/yang');
  FContentTypes.AddOrSetValue('.yin', 'application/yin+xml');
  FContentTypes.AddOrSetValue('.zip', 'application/zip');
end;

constructor TStaticModule.Create(const ABaseUri, ARootDir: string);
begin
  Create(ABaseUri);
  FRootDir := ARootDir;
end;

function TStaticModule.CreateFileStream(const RelativePath: string): TStream;
begin
  Result := TFileStream.Create(FullFileName(RelativePath), fmOpenRead + fmShareDenyWrite);
end;

procedure TStaticModule.DefineContentType(C: THttpServerContext;
  const FileName: string);
var
  ContentType: string;
begin
  if C.Response.Headers.Exists('content-type') then Exit;
  
  ContentType := FindContentType(FileName);
  if ContentType <> '' then
  begin
    C.Response.ContentType := ContentType;
  end;
end;

destructor TStaticModule.Destroy;
begin
  FIndexFiles.Free;
  FContentTypes.Free;
  inherited;
end;

function TStaticModule.FindContentType(const FileName: string): string;
var
  ContentType: string;
begin
  if not FContentTypes.TryGetValue(Lowercase(TPath.GetExtension(FileName)), ContentType) then
    ContentType := 'application/octet-stream';
//    ContentType := '';
  Result := ContentType;
end;

function TStaticModule.FullFileName(const RelativePath: string): string;
begin
  Result := TPath.Combine(RootDir, RelativePath);
end;

function TStaticModule.IsValidDir(const RelativePath: string): Boolean;
begin
  Result := TDirectory.Exists(FullFileName(RelativePath));
end;

function TStaticModule.IsValidFile(const RelativePath: string): Boolean;
begin
  Result := TFile.Exists(FullFileName(RelativePath));
end;

procedure TStaticModule.NotProcessed(C: THttpServerContext);
begin
  C.Response.StatusCode := 404;
  C.Response.Close;
end;

procedure TStaticModule.ProcessFile(C: THttpServerContext;
  const RelativePath: string);
var
  FileStream: TStream;
  FileName: string;
begin
  // todo: check for hiddenfiles
  // todo: cache-control: if conditionalGet and isCacheable and isFresh return notModified
  // todo: accept-ranges
  // todo: etag
  // todo: last-modified

  C.Response.StatusCode := 200;
  FileName := FullFileName(RelativePath);

  // set headers
  if LastModified then
    C.Response.Headers.SetValue('Last-Modified',
      TBclUtils.DateTimeToUtcString(TFile.GetLastWriteTimeUtc(FileName)));

  // content-type
  DefineContentType(C, RelativePath);

  case C.Request.MethodType of
    THttpMethod.Get:
      begin
        FileStream := CreateFileStream(RelativePath);
        try
          C.Response.ContentLength := FileStream.Size;
          C.Response.Content.CopyFrom(FileStream, 0);
        finally
          FileStream.Free;
        end;
      end;
    THttpMethod.Head:
      begin
        FileStream := CreateFileStream(RelativePath);
        try
          C.Response.ContentLength := FileStream.Size;
        finally
          FileStream.Free;
        end;
        C.Response.Close;
      end;
  end;
end;

function TStaticModule.ProcessIndex(C: THttpServerContext; const RelativePath: string): Boolean;
var
  IndexFile: string;
  FileName: string;
begin
  for IndexFile in IndexFiles do
  begin
    FileName := TPath.Combine(FullFileName(RelativePath), IndexFile);
    if TFile.Exists(FileName) then
    begin
      ProcessFile(C, FileName);
      Exit(True);
    end;
  end;

  Result := False;
end;

procedure TStaticModule.ProcessRequest(const C: THttpServerContext);
var
  PathSegment: string;
  FullUri: string;
  RelativePath: string;
  Processed: Boolean;
begin
  Processed := False;
  if not (C.Request.MethodType in [THttpMethod.Get, THttpMethod.Head]) then
  begin
    // passthrough?
    C.Response.StatusCode := 405;
    C.Response.Headers.SetValue('Allow', 'GET, HEAD');
    C.Response.Close;
    Exit;
  end;

  RelativePath := '';
  for PathSegment in GetRelativeSegments(C.Request.Uri) do
    RelativePath := RelativePath + '/' + PathSegment;
  Delete(RelativePath, 1, 1);

  if IsValidFile(RelativePath) then
  begin
    ProcessFile(C, RelativePath);
    Processed := True;
  end
  else
  if IsValidDir(RelativePath) then
  begin
    FullUri := C.Request.Uri.OriginalUri;
    if FullUri[Length(FullUri)] = '/' then
      Processed := ProcessIndex(C, RelativePath)
    else
    begin
      // if it's a dir and there is no trailing slash, then redirect to an address with trailing slash
      C.Response.StatusCode := 301;
      C.Response.Headers.SetValue('Location', FullUri + '/');
      C.Response.Close;
      Processed := True;
    end;
  end;

  if not Processed then
    NotProcessed(C);
end;

end.
