Quick.HttpServer.Types.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. { ***************************************************************************
  2. Copyright (c) 2016-2020 Kike Pérez
  3. Unit : Quick.HttpServer.Types
  4. Description : Http Server Types
  5. Author : Kike Pérez
  6. Version : 1.8
  7. Created : 30/08/2019
  8. Modified : 26/03/2020
  9. This file is part of QuickLib: https://github.com/exilon/QuickLib
  10. ***************************************************************************
  11. Licensed under the Apache License, Version 2.0 (the "License");
  12. you may not use this file except in compliance with the License.
  13. You may obtain a copy of the License at
  14. http://www.apache.org/licenses/LICENSE-2.0
  15. Unless required by applicable law or agreed to in writing, software
  16. distributed under the License is distributed on an "AS IS" BASIS,
  17. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. See the License for the specific language governing permissions and
  19. limitations under the License.
  20. *************************************************************************** }
  21. unit Quick.HttpServer.Types;
  22. {$i QuickLib.inc}
  23. interface
  24. uses
  25. SysUtils,
  26. Generics.Collections;
  27. type
  28. EControlledException = class(Exception)
  29. private
  30. fCallerClass : TClass;
  31. public
  32. constructor Create(aCaller : TObject; const aMessage : string);
  33. property CallerClass : TClass read fCallerClass write fCallerClass;
  34. end;
  35. TController = class(TInterfacedObject);
  36. TControllerClass = class of TController;
  37. TMethodVerb = (mUNKNOWN, mGET, mHEAD, mPOST, mPUT, mDELETE, mOPTIONS, mTRACE, mPATCH);
  38. TMethodVerbs = set of TMethodVerb;
  39. THttpStatusCode = (Accepted = 202,
  40. Ambiguous = 300,
  41. BadGateway = 502,
  42. BadRequest = 400,
  43. Conflict = 409,
  44. Continue = 100,
  45. Created = 201,
  46. ExpectationFailed = 417,
  47. Forbidden = 403,
  48. Found = 302,
  49. GatewayTimeout = 504,
  50. Gone = 410,
  51. HttpVersionNotSupported = 505,
  52. InternalServerError = 500,
  53. LengthRequired = 411,
  54. MethodNotAllowed = 405,
  55. Moved = 301,
  56. MovedPermanently = 301,
  57. MultipleChoices = 300,
  58. NoContent = 204,
  59. NonAuthoritativeInformation = 203,
  60. NotAcceptable = 406,
  61. NotFound = 404,
  62. NotImplemented = 501,
  63. NotModified = 304,
  64. OK = 200,
  65. PartialContent = 206,
  66. PaymentRequired = 402,
  67. PreconditionFailed = 412,
  68. ProxyAuthenticationRequired = 407,
  69. Redirect = 302,
  70. RedirectKeepVerb = 307,
  71. RedirectMethod = 303,
  72. RequestedRangeNotSatisfiable = 416,
  73. RequestEntityTooLarge = 413,
  74. RequestTimeout = 408,
  75. RequestUriTooLong = 414,
  76. ResetContent = 205,
  77. SeeOther = 303,
  78. ServiceUnavailable = 503,
  79. SwitchingProtocols = 101,
  80. TemporaryRedirect = 307,
  81. Unauthorized = 401,
  82. UnsupportedMediaType = 415,
  83. Unused = 306,
  84. UpgradeRequired = 426,
  85. UseProxy = 305);
  86. TMIMETypes = class
  87. private
  88. fMIMEList : TDictionary<string,string>;
  89. procedure FillMIME;
  90. public
  91. constructor Create;
  92. destructor Destroy; override;
  93. function GetExtensionMIMEType(const aExtension : string) : string;
  94. function GetFileMIMEType(const aFilename : string) : string;
  95. procedure AddMIME(const aExtension, aMIMEType : string);
  96. end;
  97. var
  98. MIMETypes : TMIMETypes;
  99. const
  100. MethodVerbStr: array[0..Ord(High(TMethodVerb))] of string = ('UNKNOWN','HEAD','GET','POST','PUT','DELETE','OPTIONS','TRACE','PATCH');
  101. implementation
  102. procedure TMIMETypes.AddMIME(const aExtension, aMIMEType: string);
  103. begin
  104. if not fMIMEList.ContainsKey(aExtension.ToLower) then fMIMEList.Add(aExtension.ToLower,aMIMEType.ToLower);
  105. end;
  106. constructor TMIMETypes.Create;
  107. begin
  108. fMIMEList := TDictionary<string,string>.Create(375);
  109. FillMIME;
  110. end;
  111. destructor TMIMETypes.Destroy;
  112. begin
  113. fMIMEList.Free;
  114. inherited;
  115. end;
  116. procedure TMIMETypes.FillMIME;
  117. begin
  118. { Animation }
  119. fMIMEList.Add('.nml','animation/narrative');
  120. { Audio }
  121. fMIMEList.Add('.aac','audio/mp4');
  122. fMIMEList.Add('.aif','audio/x-aiff');
  123. fMIMEList.Add('.aifc','audio/x-aiff');
  124. fMIMEList.Add('.aiff','audio/x-aiff');
  125. fMIMEList.Add('.au','audio/basic');
  126. fMIMEList.Add('.gsm','audio/x-gsm');
  127. fMIMEList.Add('.kar','audio/midi');
  128. fMIMEList.Add('.m3u','audio/mpegurl');
  129. fMIMEList.Add('.m4a','audio/x-mpg');
  130. fMIMEList.Add('.mid','audio/midi');
  131. fMIMEList.Add('.midi','audio/midi');
  132. fMIMEList.Add('.mpega','audio/x-mpg');
  133. fMIMEList.Add('.mp2','audio/x-mpg');
  134. fMIMEList.Add('.mp3','audio/x-mpg');
  135. fMIMEList.Add('.mpga','audio/x-mpg');
  136. fMIMEList.Add('.pls','audio/x-scpls');
  137. fMIMEList.Add('.qcp','audio/vnd.qcelp');
  138. fMIMEList.Add('.ra','audio/x-realaudio');
  139. fMIMEList.Add('.ram','audio/x-pn-realaudio');
  140. fMIMEList.Add('.rm','audio/x-pn-realaudio');
  141. fMIMEList.Add('.sd2','audio/x-sd2');
  142. fMIMEList.Add('.sid','audio/prs.sid');
  143. fMIMEList.Add('.snd','audio/basic');
  144. fMIMEList.Add('.wav','audio/x-wav');
  145. fMIMEList.Add('.wax','audio/x-ms-wax');
  146. fMIMEList.Add('.wma','audio/x-ms-wma');
  147. fMIMEList.Add('.mjf','audio/x-vnd.AudioExplosion.MjuiceMediaFile');
  148. { Image }
  149. fMIMEList.Add('.art','image/x-jg');
  150. fMIMEList.Add('.bmp','image/bmp');
  151. fMIMEList.Add('.cdr','image/x-coreldraw');
  152. fMIMEList.Add('.cdt','image/x-coreldrawtemplate');
  153. fMIMEList.Add('.cpt','image/x-corelphotopaint');
  154. fMIMEList.Add('.djv','image/vnd.djvu');
  155. fMIMEList.Add('.djvu','image/vnd.djvu');
  156. fMIMEList.Add('.gif','image/gif');
  157. fMIMEList.Add('.ief','image/ief');
  158. fMIMEList.Add('.ico','image/x-icon');
  159. fMIMEList.Add('.jng','image/x-jng');
  160. fMIMEList.Add('.jpg','image/jpeg');
  161. fMIMEList.Add('.jpeg','image/jpeg');
  162. fMIMEList.Add('.jpe','image/jpeg');
  163. fMIMEList.Add('.pat','image/x-coreldrawpattern');
  164. fMIMEList.Add('.pcx','image/pcx');
  165. fMIMEList.Add('.pbm','image/x-portable-bitmap');
  166. fMIMEList.Add('.pgm','image/x-portable-graymap');
  167. fMIMEList.Add('.pict','image/x-pict');
  168. fMIMEList.Add('.png','image/x-png');
  169. fMIMEList.Add('.pnm','image/x-portable-anymap');
  170. fMIMEList.Add('.pntg','image/x-macpaint');
  171. fMIMEList.Add('.ppm','image/x-portable-pixmap');
  172. fMIMEList.Add('.psd','image/x-psd');
  173. fMIMEList.Add('.qtif','image/x-quicktime');
  174. fMIMEList.Add('.ras','image/x-cmu-raster');
  175. fMIMEList.Add('.rf','image/vnd.rn-realflash');
  176. fMIMEList.Add('.rgb','image/x-rgb');
  177. fMIMEList.Add('.rp','image/vnd.rn-realpix');
  178. fMIMEList.Add('.sgi','image/x-sgi');
  179. fMIMEList.Add('.svg','image/svg+xml');
  180. fMIMEList.Add('.svgz','image/svg+xml');
  181. fMIMEList.Add('.targa','image/x-targa');
  182. fMIMEList.Add('.tif','image/x-tiff');
  183. fMIMEList.Add('.webp','image/webp');
  184. fMIMEList.Add('.xbm','image/xbm');
  185. fMIMEList.Add('.xpm','image/x-xpixmap');
  186. fMIMEList.Add('.xwd','image/x-xwindowdump');
  187. { Text }
  188. fMIMEList.Add('.323','text/h323');
  189. fMIMEList.Add('.xml','text/xml');
  190. fMIMEList.Add('.uls','text/iuls');
  191. fMIMEList.Add('.txt','text/plain');
  192. fMIMEList.Add('.rtx','text/richtext');
  193. fMIMEList.Add('.wsc','text/scriptlet');
  194. fMIMEList.Add('.rt','text/vnd.rn-realtext');
  195. fMIMEList.Add('.htt','text/webviewhtml');
  196. fMIMEList.Add('.htc','text/x-component');
  197. fMIMEList.Add('.vcf','text/x-vcard');
  198. { Video }
  199. fMIMEList.Add('.asf','video/x-ms-asf');
  200. fMIMEList.Add('.asx','video/x-ms-asf');
  201. fMIMEList.Add('.avi','video/x-msvideo');
  202. fMIMEList.Add('.dl','video/dl');
  203. fMIMEList.Add('.dv','video/dv');
  204. fMIMEList.Add('.flc','video/flc');
  205. fMIMEList.Add('.fli','video/fli');
  206. fMIMEList.Add('.gl','video/gl');
  207. fMIMEList.Add('.lsf','video/x-la-asf');
  208. fMIMEList.Add('.lsx','video/x-la-asf');
  209. fMIMEList.Add('.mng','video/x-mng');
  210. fMIMEList.Add('.mp4','video/mpeg');
  211. fMIMEList.Add('.mpeg','video/x-mpeg2a');
  212. fMIMEList.Add('.mpa','video/mpeg');
  213. fMIMEList.Add('.mpe','video/mpeg');
  214. fMIMEList.Add('.mpg','video/mpeg');
  215. fMIMEList.Add('.ogv','video/ogg');
  216. fMIMEList.Add('.moov','video/quicktime');
  217. fMIMEList.Add('.mov','video/quicktime');
  218. fMIMEList.Add('.mxu','video/vnd.mpegurl');
  219. fMIMEList.Add('.qt','video/quicktime');
  220. fMIMEList.Add('.qtc','video/x-qtc');
  221. fMIMEList.Add('.rv','video/vnd.rn-realvideo');
  222. fMIMEList.Add('.ivf','video/x-ivf');
  223. fMIMEList.Add('.webm','video/webm');
  224. fMIMEList.Add('.wm','video/x-ms-wm');
  225. fMIMEList.Add('.wmp','video/x-ms-wmp');
  226. fMIMEList.Add('.wmv','video/x-ms-wmv');
  227. fMIMEList.Add('.wmx','video/x-ms-wmx');
  228. fMIMEList.Add('.wvx','video/x-ms-wvx');
  229. fMIMEList.Add('.rms','video/vnd.rn-realvideo-secure');
  230. fMIMEList.Add('.movie','video/x-sgi-movie');
  231. { Application }
  232. fMIMEList.Add('.7z','application/x-7z-compressed');
  233. fMIMEList.Add('.a','application/x-archive');
  234. fMIMEList.Add('.aab','application/x-authorware-bin');
  235. fMIMEList.Add('.aam','application/x-authorware-map');
  236. fMIMEList.Add('.aas','application/x-authorware-seg');
  237. fMIMEList.Add('.abw','application/x-abiword');
  238. fMIMEList.Add('.ace','application/x-ace-compressed');
  239. fMIMEList.Add('.ai','application/postscript');
  240. fMIMEList.Add('.alz','application/x-alz-compressed');
  241. fMIMEList.Add('.ani','application/x-navi-animation');
  242. fMIMEList.Add('.arj','application/x-arj');
  243. fMIMEList.Add('.bat','application/x-msdos-program');
  244. fMIMEList.Add('.bcpio','application/x-bcpio');
  245. fMIMEList.Add('.boz','application/x-bzip2');
  246. fMIMEList.Add('.bz','application/x-bzip');
  247. fMIMEList.Add('.bz2','application/x-bzip2');
  248. fMIMEList.Add('.cab','application/vnd.ms-cab-compressed');
  249. fMIMEList.Add('.cat','application/vnd.ms-pki.seccat');
  250. fMIMEList.Add('.ccn','application/x-cnc');
  251. fMIMEList.Add('.cco','application/x-cocoa');
  252. fMIMEList.Add('.cdf','application/x-cdf');
  253. fMIMEList.Add('.cer','application/x-x509-ca-cert');
  254. fMIMEList.Add('.chm','application/vnd.ms-htmlhelp');
  255. fMIMEList.Add('.chrt','application/vnd.kde.kchart');
  256. fMIMEList.Add('.cil','application/vnd.ms-artgalry');
  257. fMIMEList.Add('.class','application/java-vm');
  258. fMIMEList.Add('.com','application/x-msdos-program');
  259. fMIMEList.Add('.clp','application/x-msclip');
  260. fMIMEList.Add('.cpio','application/x-cpio');
  261. fMIMEList.Add('.cqk','application/x-calquick');
  262. fMIMEList.Add('.crd','application/x-mscardfile');
  263. fMIMEList.Add('.crl','application/pkix-crl');
  264. fMIMEList.Add('.csh','application/x-csh');
  265. fMIMEList.Add('.dar','application/x-dar');
  266. fMIMEList.Add('.dbf','application/x-dbase');
  267. fMIMEList.Add('.dcr','application/x-director');
  268. fMIMEList.Add('.deb','application/x-debian-package');
  269. fMIMEList.Add('.dir','application/x-director');
  270. fMIMEList.Add('.dist','vnd.apple.installer+xml');
  271. fMIMEList.Add('.distz','vnd.apple.installer+xml');
  272. fMIMEList.Add('.dll','application/x-msdos-program');
  273. fMIMEList.Add('.dmg','application/x-apple-diskimage');
  274. fMIMEList.Add('.doc','application/msword');
  275. fMIMEList.Add('.dot','application/msword');
  276. fMIMEList.Add('.dvi','application/x-dvi');
  277. fMIMEList.Add('.dxr','application/x-director');
  278. fMIMEList.Add('.ebk','application/x-expandedbook');
  279. fMIMEList.Add('.eps','application/postscript');
  280. fMIMEList.Add('.evy','application/envoy');
  281. fMIMEList.Add('.exe','application/x-msdos-program');
  282. fMIMEList.Add('.fdf','application/vnd.fdf');
  283. fMIMEList.Add('.fif','application/fractals');
  284. fMIMEList.Add('.flm','application/vnd.kde.kivio');
  285. fMIMEList.Add('.fml','application/x-file-mirror-list');
  286. fMIMEList.Add('.gzip','application/x-gzip');
  287. fMIMEList.Add('.gnumeric','application/x-gnumeric');
  288. fMIMEList.Add('.gtar','application/x-gtar');
  289. fMIMEList.Add('.gz','application/x-gzip');
  290. fMIMEList.Add('.hdf','application/x-hdf');
  291. fMIMEList.Add('.hlp','application/winhlp');
  292. fMIMEList.Add('.hpf','application/x-icq-hpf');
  293. fMIMEList.Add('.hqx','application/mac-binhex40');
  294. fMIMEList.Add('.hta','application/hta');
  295. fMIMEList.Add('.ims','application/vnd.ms-ims');
  296. fMIMEList.Add('.ins','application/x-internet-signup');
  297. fMIMEList.Add('.iii','application/x-iphone');
  298. fMIMEList.Add('.iso','application/x-iso9660-image');
  299. fMIMEList.Add('.jar','application/java-archive');
  300. fMIMEList.Add('.karbon','application/vnd.kde.karbon');
  301. fMIMEList.Add('.kfo','application/vnd.kde.kformula');
  302. fMIMEList.Add('.kon','application/vnd.kde.kontour');
  303. fMIMEList.Add('.kpr','application/vnd.kde.kpresenter');
  304. fMIMEList.Add('.kpt','application/vnd.kde.kpresenter');
  305. fMIMEList.Add('.kwd','application/vnd.kde.kword');
  306. fMIMEList.Add('.kwt','application/vnd.kde.kword');
  307. fMIMEList.Add('.latex','application/x-latex');
  308. fMIMEList.Add('.lha','application/x-lzh');
  309. fMIMEList.Add('.lcc','application/fastman');
  310. fMIMEList.Add('.lrm','application/vnd.ms-lrm');
  311. fMIMEList.Add('.lz','application/x-lzip');
  312. fMIMEList.Add('.lzh','application/x-lzh');
  313. fMIMEList.Add('.lzma','application/x-lzma');
  314. fMIMEList.Add('.lzo','application/x-lzop');
  315. fMIMEList.Add('.lzx','application/x-lzx');
  316. fMIMEList.Add('.m13','application/x-msmediaview');
  317. fMIMEList.Add('.m14','application/x-msmediaview');
  318. fMIMEList.Add('.mpp','application/vnd.ms-project');
  319. fMIMEList.Add('.mvb','application/x-msmediaview');
  320. fMIMEList.Add('.man','application/x-troff-man');
  321. fMIMEList.Add('.mdb','application/x-msaccess');
  322. fMIMEList.Add('.me','application/x-troff-me');
  323. fMIMEList.Add('.ms','application/x-troff-ms');
  324. fMIMEList.Add('.msi','application/x-msi');
  325. fMIMEList.Add('.mpkg','vnd.apple.installer+xml');
  326. fMIMEList.Add('.mny','application/x-msmoney');
  327. fMIMEList.Add('.nix','application/x-mix-transfer');
  328. fMIMEList.Add('.o','application/x-object');
  329. fMIMEList.Add('.oda','application/oda');
  330. fMIMEList.Add('.odb','application/vnd.oasis.opendocument.database');
  331. fMIMEList.Add('.odc','application/vnd.oasis.opendocument.chart');
  332. fMIMEList.Add('.odf','application/vnd.oasis.opendocument.formula');
  333. fMIMEList.Add('.odg','application/vnd.oasis.opendocument.graphics');
  334. fMIMEList.Add('.odi','application/vnd.oasis.opendocument.image');
  335. fMIMEList.Add('.odm','application/vnd.oasis.opendocument.text-master');
  336. fMIMEList.Add('.odp','application/vnd.oasis.opendocument.presentation');
  337. fMIMEList.Add('.ods','application/vnd.oasis.opendocument.spreadsheet');
  338. fMIMEList.Add('.ogg','application/ogg');
  339. fMIMEList.Add('.odt','application/vnd.oasis.opendocument.text');
  340. fMIMEList.Add('.otg','application/vnd.oasis.opendocument.graphics-template');
  341. fMIMEList.Add('.oth','application/vnd.oasis.opendocument.text-web');
  342. fMIMEList.Add('.otp','application/vnd.oasis.opendocument.presentation-template');
  343. fMIMEList.Add('.ots','application/vnd.oasis.opendocument.spreadsheet-template');
  344. fMIMEList.Add('.ott','application/vnd.oasis.opendocument.text-template');
  345. fMIMEList.Add('.p10','application/pkcs10');
  346. fMIMEList.Add('.p12','application/x-pkcs12');
  347. fMIMEList.Add('.p7b','application/x-pkcs7-certificates');
  348. fMIMEList.Add('.p7m','application/pkcs7-mime');
  349. fMIMEList.Add('.p7r','application/x-pkcs7-certreqresp');
  350. fMIMEList.Add('.p7s','application/pkcs7-signature');
  351. fMIMEList.Add('.package','application/vnd.autopackage');
  352. fMIMEList.Add('.pfr','application/font-tdpfr');
  353. fMIMEList.Add('.pkg','vnd.apple.installer+xml');
  354. fMIMEList.Add('.pdf','application/pdf');
  355. fMIMEList.Add('.pko','application/vnd.ms-pki.pko');
  356. fMIMEList.Add('.pl','application/x-perl');
  357. fMIMEList.Add('.pnq','application/x-icq-pnq');
  358. fMIMEList.Add('.pot','application/mspowerpoint');
  359. fMIMEList.Add('.pps','application/mspowerpoint');
  360. fMIMEList.Add('.ppt','application/mspowerpoint');
  361. fMIMEList.Add('.ppz','application/mspowerpoint');
  362. fMIMEList.Add('.ps','application/postscript');
  363. fMIMEList.Add('.pub','application/x-mspublisher');
  364. fMIMEList.Add('.qpw','application/x-quattropro');
  365. fMIMEList.Add('.qtl','application/x-quicktimeplayer');
  366. fMIMEList.Add('.rar','application/rar');
  367. fMIMEList.Add('.rjs','application/vnd.rn-realsystem-rjs');
  368. fMIMEList.Add('.rmf','application/vnd.rmf');
  369. fMIMEList.Add('.rmp','application/vnd.rn-rn_music_package');
  370. fMIMEList.Add('.rmx','application/vnd.rn-realsystem-rmx');
  371. fMIMEList.Add('.rnx','application/vnd.rn-realplayer');
  372. fMIMEList.Add('.rpm','application/x-redhat-package-manager');
  373. fMIMEList.Add('.rsml','application/vnd.rn-rsml');
  374. fMIMEList.Add('.rtsp','application/x-rtsp');
  375. fMIMEList.Add('.scm','application/x-icq-scm');
  376. fMIMEList.Add('.ser','application/java-serialized-object');
  377. fMIMEList.Add('.scd','application/x-msschedule');
  378. fMIMEList.Add('.sda','application/vnd.stardivision.draw');
  379. fMIMEList.Add('.sdc','application/vnd.stardivision.calc');
  380. fMIMEList.Add('.sdd','application/vnd.stardivision.impress');
  381. fMIMEList.Add('.sdp','application/x-sdp');
  382. fMIMEList.Add('.setpay','application/set-payment-initiation');
  383. fMIMEList.Add('.setreg','application/set-registration-initiation');
  384. fMIMEList.Add('.sh','application/x-sh');
  385. fMIMEList.Add('.shar','application/x-shar');
  386. fMIMEList.Add('.shw','application/presentations');
  387. fMIMEList.Add('.sit','application/x-stuffit');
  388. fMIMEList.Add('.sitx','application/x-stuffitx');
  389. fMIMEList.Add('.skd','application/x-koan');
  390. fMIMEList.Add('.skm','application/x-koan');
  391. fMIMEList.Add('.skp','application/x-koan');
  392. fMIMEList.Add('.skt','application/x-koan');
  393. fMIMEList.Add('.smf','application/vnd.stardivision.math');
  394. fMIMEList.Add('.smi','application/smil');
  395. fMIMEList.Add('.smil','application/smil');
  396. fMIMEList.Add('.spl','application/futuresplash');
  397. fMIMEList.Add('.ssm','application/streamingmedia');
  398. fMIMEList.Add('.sst','application/vnd.ms-pki.certstore');
  399. fMIMEList.Add('.stc','application/vnd.sun.xml.calc.template');
  400. fMIMEList.Add('.std','application/vnd.sun.xml.draw.template');
  401. fMIMEList.Add('.sti','application/vnd.sun.xml.impress.template');
  402. fMIMEList.Add('.stl','application/vnd.ms-pki.stl');
  403. fMIMEList.Add('.stw','application/vnd.sun.xml.writer.template');
  404. fMIMEList.Add('.svi','application/softvision');
  405. fMIMEList.Add('.sv4cpio','application/x-sv4cpio');
  406. fMIMEList.Add('.sv4crc','application/x-sv4crc');
  407. fMIMEList.Add('.swf','application/x-shockwave-flash');
  408. fMIMEList.Add('.swf1','application/x-shockwave-flash');
  409. fMIMEList.Add('.sxc','application/vnd.sun.xml.calc');
  410. fMIMEList.Add('.sxi','application/vnd.sun.xml.impress');
  411. fMIMEList.Add('.sxm','application/vnd.sun.xml.math');
  412. fMIMEList.Add('.sxw','application/vnd.sun.xml.writer');
  413. fMIMEList.Add('.sxg','application/vnd.sun.xml.writer.global');
  414. fMIMEList.Add('.t','application/x-troff');
  415. fMIMEList.Add('.tar','application/x-tar');
  416. fMIMEList.Add('.tcl','application/x-tcl');
  417. fMIMEList.Add('.tex','application/x-tex');
  418. fMIMEList.Add('.texi','application/x-texinfo');
  419. fMIMEList.Add('.texinfo','application/x-texinfo');
  420. fMIMEList.Add('.tbz','application/x-bzip-compressed-tar');
  421. fMIMEList.Add('.tbz2','application/x-bzip-compressed-tar');
  422. fMIMEList.Add('.tgz','application/x-compressed-tar');
  423. fMIMEList.Add('.tlz','application/x-lzma-compressed-tar');
  424. fMIMEList.Add('.tr','application/x-troff');
  425. fMIMEList.Add('.trm','application/x-msterminal');
  426. fMIMEList.Add('.troff','application/x-troff');
  427. fMIMEList.Add('.tsp','application/dsptype');
  428. fMIMEList.Add('.torrent','application/x-bittorrent');
  429. fMIMEList.Add('.ttz','application/t-time');
  430. fMIMEList.Add('.txz','application/x-xz-compressed-tar');
  431. fMIMEList.Add('.udeb','application/x-debian-package');
  432. fMIMEList.Add('.uin','application/x-icq');
  433. fMIMEList.Add('.urls','application/x-url-list');
  434. fMIMEList.Add('.ustar','application/x-ustar');
  435. fMIMEList.Add('.vcd','application/x-cdlink');
  436. fMIMEList.Add('.vor','application/vnd.stardivision.writer');
  437. fMIMEList.Add('.vsl','application/x-cnet-vsl');
  438. fMIMEList.Add('.wcm','application/vnd.ms-works');
  439. fMIMEList.Add('.wb1','application/x-quattropro');
  440. fMIMEList.Add('.wb2','application/x-quattropro');
  441. fMIMEList.Add('.wb3','application/x-quattropro');
  442. fMIMEList.Add('.wdb','application/vnd.ms-works');
  443. fMIMEList.Add('.wks','application/vnd.ms-works');
  444. fMIMEList.Add('.wmd','application/x-ms-wmd');
  445. fMIMEList.Add('.wms','application/x-ms-wms');
  446. fMIMEList.Add('.wmz','application/x-ms-wmz');
  447. fMIMEList.Add('.wp5','application/wordperfect5.1');
  448. fMIMEList.Add('.wpd','application/wordperfect');
  449. fMIMEList.Add('.wpl','application/vnd.ms-wpl');
  450. fMIMEList.Add('.wps','application/vnd.ms-works');
  451. fMIMEList.Add('.wri','application/x-mswrite');
  452. fMIMEList.Add('.xfdf','application/vnd.adobe.xfdf');
  453. fMIMEList.Add('.xls','application/x-msexcel');
  454. fMIMEList.Add('.xlb','application/x-msexcel');
  455. fMIMEList.Add('.xpi','application/x-xpinstall');
  456. fMIMEList.Add('.xps','application/vnd.ms-xpsdocument');
  457. fMIMEList.Add('.xsd','application/vnd.sun.xml.draw');
  458. fMIMEList.Add('.xul','application/vnd.mozilla.xul+xml');
  459. fMIMEList.Add('.z','application/x-compress');
  460. fMIMEList.Add('.zoo','application/x-zoo');
  461. fMIMEList.Add('.zip','application/x-zip-compressed');
  462. { WAP }
  463. fMIMEList.Add('.wbmp','image/vnd.wap.wbmp');
  464. fMIMEList.Add('.wml','text/vnd.wap.wml');
  465. fMIMEList.Add('.wmlc','application/vnd.wap.wmlc');
  466. fMIMEList.Add('.wmls','text/vnd.wap.wmlscript');
  467. fMIMEList.Add('.wmlsc','application/vnd.wap.wmlscriptc');
  468. { Non-web text}
  469. fMIMEList.Add('.asm','text/x-asm');
  470. fMIMEList.Add('.p','text/x-pascal');
  471. fMIMEList.Add('.pas','text/x-pascal');
  472. fMIMEList.Add('.cs','text/x-csharp');
  473. fMIMEList.Add('.c','text/x-csrc');
  474. fMIMEList.Add('.c++','text/x-c++src');
  475. fMIMEList.Add('.cpp','text/x-c++src');
  476. fMIMEList.Add('.cxx','text/x-c++src');
  477. fMIMEList.Add('.cc','text/x-c++src');
  478. fMIMEList.Add('.h','text/x-chdr');
  479. fMIMEList.Add('.h++','text/x-c++hdr');
  480. fMIMEList.Add('.hpp','text/x-c++hdr');
  481. fMIMEList.Add('.hxx','text/x-c++hdr');
  482. fMIMEList.Add('.hh','text/x-c++hdr');
  483. fMIMEList.Add('.java','text/x-java');
  484. { WEB }
  485. fMIMEList.Add('.css','text/css');
  486. fMIMEList.Add('.js','text/javascript');
  487. fMIMEList.Add('.htm','text/html');
  488. fMIMEList.Add('.html','text/html');
  489. fMIMEList.Add('.xhtml','application/xhtml+xml');
  490. fMIMEList.Add('.xht','application/xhtml+xml');
  491. fMIMEList.Add('.rdf','application/rdf+xml');
  492. fMIMEList.Add('.rss','application/rss+xml');
  493. fMIMEList.Add('.ls','text/javascript');
  494. fMIMEList.Add('.mocha','text/javascript');
  495. fMIMEList.Add('.shtml','server-parsed-html');
  496. fMIMEList.Add('.sgm','text/sgml');
  497. fMIMEList.Add('.sgml','text/sgml');
  498. { Message }
  499. fMIMEList.Add('.mht','message/rfc822');
  500. end;
  501. function TMIMETypes.GetExtensionMIMEType(const aExtension: string): string;
  502. begin
  503. if not fMIMEList.TryGetValue(aExtension,Result) then Result := 'text/html';
  504. end;
  505. function TMIMETypes.GetFileMIMEType(const aFilename: string): string;
  506. var
  507. fname : string;
  508. begin
  509. fname := ExtractFileExt(aFilename);
  510. //remove queries
  511. if fname.Contains('?') then fname := Copy(fname,1,fname.IndexOf('?'));
  512. if not fMIMEList.TryGetValue(fname,Result) then Result := 'text/html';
  513. end;
  514. { EControlledException }
  515. constructor EControlledException.Create(aCaller: TObject; const aMessage: string);
  516. begin
  517. inherited Create(aMessage);
  518. if aCaller <> nil then fCallerClass := aCaller.ClassType;
  519. end;
  520. initialization
  521. MIMETypes := TMIMETypes.Create;
  522. finalization
  523. MIMETypes.Free;
  524. end.