1
0

FileServer.st 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. Object subclass: #FileServer
  2. instanceVariableNames: 'path http fs url port basePath sys'
  3. category: 'FileServer'!
  4. !FileServer methodsFor: 'accessing'!
  5. basePath
  6. ^basePath ifNil: ['./']
  7. !
  8. basePath: aString
  9. basePath := aString
  10. !
  11. port
  12. ^self class port
  13. ! !
  14. !FileServer methodsFor: 'initialization'!
  15. initialize
  16. super initialize.
  17. path := self require: 'path'.
  18. http := self require: 'http'.
  19. fs := self require: 'fs'.
  20. sys := self require: 'sys'.
  21. url := self require: 'url'
  22. ! !
  23. !FileServer methodsFor: 'private'!
  24. require: aModuleString
  25. "call to the require function"
  26. ^require value: aModuleString
  27. !
  28. writeData: data toFileNamed: aFilename
  29. console log: aFilename
  30. ! !
  31. !FileServer methodsFor: 'request handling'!
  32. respondNotFoundTo: aResponse
  33. aResponse
  34. writeHead: 404 options: #{'Content-Type' -> 'text/plain'};
  35. write: '404 Not found';
  36. end
  37. !
  38. handleRequest: aRequest respondTo: aResponse
  39. aRequest method = 'PUT'
  40. ifTrue: [self handlePUTRequest: aRequest respondTo: aResponse]
  41. ifFalse: [self handleGETRequest: aRequest respondTo: aResponse]
  42. !
  43. handleGETRequest: aRequest respondTo: aResponse
  44. | uri filename |
  45. uri := (url parse: aRequest url) pathname.
  46. filename := path join: self basePath with: uri.
  47. path exists: filename do: [:boolean |
  48. boolean
  49. ifFalse: [self respondNotFoundTo: aResponse]
  50. ifTrue: [self respondFileNamed: filename to: aResponse]]
  51. !
  52. handlePUTRequest: aRequest respondTo: aResponse
  53. | stream |
  54. stream := fs createWriteStream: '.', aRequest url.
  55. aRequest setEncoding: 'utf8'.
  56. aRequest on: #data do: [:data | stream write: data].
  57. aRequest on: #end do: [
  58. stream end.
  59. self respondOKTo: aResponse]
  60. !
  61. respondFileNamed: aFilename to: aResponse
  62. | type filename |
  63. filename := aFilename.
  64. (fs statSync: aFilename) isDirectory ifTrue: [
  65. filename := filename, 'index.html'].
  66. fs readFile: filename do: [:ex :file |
  67. ex notNil
  68. ifTrue: [self respondInternalErrorTo: aResponse]
  69. ifFalse: [
  70. type := self class mimeTypeFor: filename.
  71. aResponse
  72. writeHead: 200 options: #{'Content-Type' -> type};
  73. write: file binary: 'binary';
  74. end]]
  75. !
  76. respondInternalErrorTo: aResponse
  77. aResponse
  78. writeHead: 500 options: #{'Content-Type' -> 'text/plain'};
  79. write: '500 Internal server error';
  80. end
  81. !
  82. respondOKTo: aResponse
  83. aResponse
  84. writeHead: 200 options: #{'Content-Type' -> 'text/plain'};
  85. end
  86. ! !
  87. !FileServer methodsFor: 'starting'!
  88. startOn: aPort
  89. port := aPort.
  90. self start
  91. !
  92. start
  93. (http createServer: [:request :response |
  94. self handleRequest: request respondTo: response]) listen: self port.
  95. console log: 'Starting file server on port ', self port asString
  96. ! !
  97. FileServer class instanceVariableNames: 'port mimeTypes'!
  98. !FileServer class methodsFor: 'accessing'!
  99. port
  100. ^port ifNil: [4000]
  101. !
  102. port: aNumber
  103. port := aNumber
  104. !
  105. defaultMimeTypes
  106. ^ #{
  107. '%' -> 'application/x-trash'.
  108. '323' -> 'text/h323'.
  109. 'abw' -> 'application/x-abiword'.
  110. 'ai' -> 'application/postscript'.
  111. 'aif' -> 'audio/x-aiff'.
  112. 'aifc' -> 'audio/x-aiff'.
  113. 'aiff' -> 'audio/x-aiff'.
  114. 'alc' -> 'chemical/x-alchemy'.
  115. 'art' -> 'image/x-jg'.
  116. 'asc' -> 'text/plain'.
  117. 'asf' -> 'video/x-ms-asf'.
  118. 'asn' -> 'chemical/x-ncbi-asn1-spec'.
  119. 'aso' -> 'chemical/x-ncbi-asn1-binary'.
  120. 'asx' -> 'video/x-ms-asf'.
  121. 'au' -> 'audio/basic'.
  122. 'avi' -> 'video/x-msvideo'.
  123. 'b' -> 'chemical/x-molconn-Z'.
  124. 'bak' -> 'application/x-trash'.
  125. 'bat' -> 'application/x-msdos-program'.
  126. 'bcpio' -> 'application/x-bcpio'.
  127. 'bib' -> 'text/x-bibtex'.
  128. 'bin' -> 'application/octet-stream'.
  129. 'bmp' -> 'image/x-ms-bmp'.
  130. 'book' -> 'application/x-maker'.
  131. 'bsd' -> 'chemical/x-crossfire'.
  132. 'c' -> 'text/x-csrc'.
  133. 'c++' -> 'text/x-c++src'.
  134. 'c3d' -> 'chemical/x-chem3d'.
  135. 'cac' -> 'chemical/x-cache'.
  136. 'cache' -> 'chemical/x-cache'.
  137. 'cascii' -> 'chemical/x-cactvs-binary'.
  138. 'cat' -> 'application/vnd.ms-pki.seccat'.
  139. 'cbin' -> 'chemical/x-cactvs-binary'.
  140. 'cc' -> 'text/x-c++src'.
  141. 'cdf' -> 'application/x-cdf'.
  142. 'cdr' -> 'image/x-coreldraw'.
  143. 'cdt' -> 'image/x-coreldrawtemplate'.
  144. 'cdx' -> 'chemical/x-cdx'.
  145. 'cdy' -> 'application/vnd.cinderella'.
  146. 'cef' -> 'chemical/x-cxf'.
  147. 'cer' -> 'chemical/x-cerius'.
  148. 'chm' -> 'chemical/x-chemdraw'.
  149. 'chrt' -> 'application/x-kchart'.
  150. 'cif' -> 'chemical/x-cif'.
  151. 'class' -> 'application/java-vm'.
  152. 'cls' -> 'text/x-tex'.
  153. 'cmdf' -> 'chemical/x-cmdf'.
  154. 'cml' -> 'chemical/x-cml'.
  155. 'cod' -> 'application/vnd.rim.cod'.
  156. 'com' -> 'application/x-msdos-program'.
  157. 'cpa' -> 'chemical/x-compass'.
  158. 'cpio' -> 'application/x-cpio'.
  159. 'cpp' -> 'text/x-c++src'.
  160. 'cpt' -> 'image/x-corelphotopaint'.
  161. 'crl' -> 'application/x-pkcs7-crl'.
  162. 'crt' -> 'application/x-x509-ca-cert'.
  163. 'csf' -> 'chemical/x-cache-csf'.
  164. 'csh' -> 'text/x-csh'.
  165. 'csm' -> 'chemical/x-csml'.
  166. 'csml' -> 'chemical/x-csml'.
  167. 'css' -> 'text/css'.
  168. 'csv' -> 'text/comma-separated-values'.
  169. 'ctab' -> 'chemical/x-cactvs-binary'.
  170. 'ctx' -> 'chemical/x-ctx'.
  171. 'cu' -> 'application/cu-seeme'.
  172. 'cub' -> 'chemical/x-gaussian-cube'.
  173. 'cxf' -> 'chemical/x-cxf'.
  174. 'cxx' -> 'text/x-c++src'.
  175. 'dat' -> 'chemical/x-mopac-input'.
  176. 'dcr' -> 'application/x-director'.
  177. 'deb' -> 'application/x-debian-package'.
  178. 'dif' -> 'video/dv'.
  179. 'diff' -> 'text/plain'.
  180. 'dir' -> 'application/x-director'.
  181. 'djv' -> 'image/vnd.djvu'.
  182. 'djvu' -> 'image/vnd.djvu'.
  183. 'dl' -> 'video/dl'.
  184. 'dll' -> 'application/x-msdos-program'.
  185. 'dmg' -> 'application/x-apple-diskimage'.
  186. 'dms' -> 'application/x-dms'.
  187. 'doc' -> 'application/msword'.
  188. 'dot' -> 'application/msword'.
  189. 'dv' -> 'video/dv'.
  190. 'dvi' -> 'application/x-dvi'.
  191. 'dx' -> 'chemical/x-jcamp-dx'.
  192. 'dxr' -> 'application/x-director'.
  193. 'emb' -> 'chemical/x-embl-dl-nucleotide'.
  194. 'embl' -> 'chemical/x-embl-dl-nucleotide'.
  195. 'ent' -> 'chemical/x-pdb'.
  196. 'eps' -> 'application/postscript'.
  197. 'etx' -> 'text/x-setext'.
  198. 'exe' -> 'application/x-msdos-program'.
  199. 'ez' -> 'application/andrew-inset'.
  200. 'fb' -> 'application/x-maker'.
  201. 'fbdoc' -> 'application/x-maker'.
  202. 'fch' -> 'chemical/x-gaussian-checkpoint'.
  203. 'fchk' -> 'chemical/x-gaussian-checkpoint'.
  204. 'fig' -> 'application/x-xfig'.
  205. 'flac' -> 'application/x-flac'.
  206. 'fli' -> 'video/fli'.
  207. 'fm' -> 'application/x-maker'.
  208. 'frame' -> 'application/x-maker'.
  209. 'frm' -> 'application/x-maker'.
  210. 'gal' -> 'chemical/x-gaussian-log'.
  211. 'gam' -> 'chemical/x-gamess-input'.
  212. 'gamin' -> 'chemical/x-gamess-input'.
  213. 'gau' -> 'chemical/x-gaussian-input'.
  214. 'gcd' -> 'text/x-pcs-gcd'.
  215. 'gcf' -> 'application/x-graphing-calculator'.
  216. 'gcg' -> 'chemical/x-gcg8-sequence'.
  217. 'gen' -> 'chemical/x-genbank'.
  218. 'gf' -> 'application/x-tex-gf'.
  219. 'gif' -> 'image/gif'.
  220. 'gjc' -> 'chemical/x-gaussian-input'.
  221. 'gjf' -> 'chemical/x-gaussian-input'.
  222. 'gl' -> 'video/gl'.
  223. 'gnumeric' -> 'application/x-gnumeric'.
  224. 'gpt' -> 'chemical/x-mopac-graph'.
  225. 'gsf' -> 'application/x-font'.
  226. 'gsm' -> 'audio/x-gsm'.
  227. 'gtar' -> 'application/x-gtar'.
  228. 'h' -> 'text/x-chdr'.
  229. 'h++' -> 'text/x-c++hdr'.
  230. 'hdf' -> 'application/x-hdf'.
  231. 'hh' -> 'text/x-c++hdr'.
  232. 'hin' -> 'chemical/x-hin'.
  233. 'hpp' -> 'text/x-c++hdr'.
  234. 'hqx' -> 'application/mac-binhex40'.
  235. 'hs' -> 'text/x-haskell'.
  236. 'hta' -> 'application/hta'.
  237. 'htc' -> 'text/x-component'.
  238. 'htm' -> 'text/html'.
  239. 'html' -> 'text/html'.
  240. 'hxx' -> 'text/x-c++hdr'.
  241. 'ica' -> 'application/x-ica'.
  242. 'ice' -> 'x-conference/x-cooltalk'.
  243. 'ico' -> 'image/x-icon'.
  244. 'ics' -> 'text/calendar'.
  245. 'icz' -> 'text/calendar'.
  246. 'ief' -> 'image/ief'.
  247. 'iges' -> 'model/iges'.
  248. 'igs' -> 'model/iges'.
  249. 'iii' -> 'application/x-iphone'.
  250. 'inp' -> 'chemical/x-gamess-input'.
  251. 'ins' -> 'application/x-internet-signup'.
  252. 'iso' -> 'application/x-iso9660-image'.
  253. 'isp' -> 'application/x-internet-signup'.
  254. 'ist' -> 'chemical/x-isostar'.
  255. 'istr' -> 'chemical/x-isostar'.
  256. 'jad' -> 'text/vnd.sun.j2me.app-descriptor'.
  257. 'jar' -> 'application/java-archive'.
  258. 'java' -> 'text/x-java'.
  259. 'jdx' -> 'chemical/x-jcamp-dx'.
  260. 'jmz' -> 'application/x-jmol'.
  261. 'jng' -> 'image/x-jng'.
  262. 'jnlp' -> 'application/x-java-jnlp-file'.
  263. 'jpe' -> 'image/jpeg'.
  264. 'jpeg' -> 'image/jpeg'.
  265. 'jpg' -> 'image/jpeg'.
  266. 'js' -> 'application/javascript'.
  267. 'kar' -> 'audio/midi'.
  268. 'key' -> 'application/pgp-keys'.
  269. 'kil' -> 'application/x-killustrator'.
  270. 'kin' -> 'chemical/x-kinemage'.
  271. 'kpr' -> 'application/x-kpresenter'.
  272. 'kpt' -> 'application/x-kpresenter'.
  273. 'ksp' -> 'application/x-kspread'.
  274. 'kwd' -> 'application/x-kword'.
  275. 'kwt' -> 'application/x-kword'.
  276. 'latex' -> 'application/x-latex'.
  277. 'lha' -> 'application/x-lha'.
  278. 'lhs' -> 'text/x-literate-haskell'.
  279. 'lsf' -> 'video/x-la-asf'.
  280. 'lsx' -> 'video/x-la-asf'.
  281. 'ltx' -> 'text/x-tex'.
  282. 'lzh' -> 'application/x-lzh'.
  283. 'lzx' -> 'application/x-lzx'.
  284. 'm3u' -> 'audio/x-mpegurl'.
  285. 'm4a' -> 'audio/mpeg'.
  286. 'maker' -> 'application/x-maker'.
  287. 'man' -> 'application/x-troff-man'.
  288. 'mcif' -> 'chemical/x-mmcif'.
  289. 'mcm' -> 'chemical/x-macmolecule'.
  290. 'mdb' -> 'application/msaccess'.
  291. 'me' -> 'application/x-troff-me'.
  292. 'mesh' -> 'model/mesh'.
  293. 'mid' -> 'audio/midi'.
  294. 'midi' -> 'audio/midi'.
  295. 'mif' -> 'application/x-mif'.
  296. 'mm' -> 'application/x-freemind'.
  297. 'mmd' -> 'chemical/x-macromodel-input'.
  298. 'mmf' -> 'application/vnd.smaf'.
  299. 'mml' -> 'text/mathml'.
  300. 'mmod' -> 'chemical/x-macromodel-input'.
  301. 'mng' -> 'video/x-mng'.
  302. 'moc' -> 'text/x-moc'.
  303. 'mol' -> 'chemical/x-mdl-molfile'.
  304. 'mol2' -> 'chemical/x-mol2'.
  305. 'moo' -> 'chemical/x-mopac-out'.
  306. 'mop' -> 'chemical/x-mopac-input'.
  307. 'mopcrt' -> 'chemical/x-mopac-input'.
  308. 'mov' -> 'video/quicktime'.
  309. 'movie' -> 'video/x-sgi-movie'.
  310. 'mp2' -> 'audio/mpeg'.
  311. 'mp3' -> 'audio/mpeg'.
  312. 'mp4' -> 'video/mp4'.
  313. 'mpc' -> 'chemical/x-mopac-input'.
  314. 'mpe' -> 'video/mpeg'.
  315. 'mpeg' -> 'video/mpeg'.
  316. 'mpega' -> 'audio/mpeg'.
  317. 'mpg' -> 'video/mpeg'.
  318. 'mpga' -> 'audio/mpeg'.
  319. 'ms' -> 'application/x-troff-ms'.
  320. 'msh' -> 'model/mesh'.
  321. 'msi' -> 'application/x-msi'.
  322. 'mvb' -> 'chemical/x-mopac-vib'.
  323. 'mxu' -> 'video/vnd.mpegurl'.
  324. 'nb' -> 'application/mathematica'.
  325. 'nc' -> 'application/x-netcdf'.
  326. 'nwc' -> 'application/x-nwc'.
  327. 'o' -> 'application/x-object'.
  328. 'oda' -> 'application/oda'.
  329. 'odb' -> 'application/vnd.oasis.opendocument.database'.
  330. 'odc' -> 'application/vnd.oasis.opendocument.chart'.
  331. 'odf' -> 'application/vnd.oasis.opendocument.formula'.
  332. 'odg' -> 'application/vnd.oasis.opendocument.graphics'.
  333. 'odi' -> 'application/vnd.oasis.opendocument.image'.
  334. 'odm' -> 'application/vnd.oasis.opendocument.text-master'.
  335. 'odp' -> 'application/vnd.oasis.opendocument.presentation'.
  336. 'ods' -> 'application/vnd.oasis.opendocument.spreadsheet'.
  337. 'odt' -> 'application/vnd.oasis.opendocument.text'.
  338. 'ogg' -> 'application/ogg'.
  339. 'old' -> 'application/x-trash'.
  340. 'oth' -> 'application/vnd.oasis.opendocument.text-web'.
  341. 'oza' -> 'application/x-oz-application'.
  342. 'p' -> 'text/x-pascal'.
  343. 'p7r' -> 'application/x-pkcs7-certreqresp'.
  344. 'pac' -> 'application/x-ns-proxy-autoconfig'.
  345. 'pas' -> 'text/x-pascal'.
  346. 'pat' -> 'image/x-coreldrawpattern'.
  347. 'pbm' -> 'image/x-portable-bitmap'.
  348. 'pcf' -> 'application/x-font'.
  349. 'pcf.Z' -> 'application/x-font'.
  350. 'pcx' -> 'image/pcx'.
  351. 'pdb' -> 'chemical/x-pdb'.
  352. 'pdf' -> 'application/pdf'.
  353. 'pfa' -> 'application/x-font'.
  354. 'pfb' -> 'application/x-font'.
  355. 'pgm' -> 'image/x-portable-graymap'.
  356. 'pgn' -> 'application/x-chess-pgn'.
  357. 'pgp' -> 'application/pgp-signature'.
  358. 'pk' -> 'application/x-tex-pk'.
  359. 'pl' -> 'text/x-perl'.
  360. 'pls' -> 'audio/x-scpls'.
  361. 'pm' -> 'text/x-perl'.
  362. 'png' -> 'image/png'.
  363. 'pnm' -> 'image/x-portable-anymap'.
  364. 'pot' -> 'text/plain'.
  365. 'ppm' -> 'image/x-portable-pixmap'.
  366. 'pps' -> 'application/vnd.ms-powerpoint'.
  367. 'ppt' -> 'application/vnd.ms-powerpoint'.
  368. 'prf' -> 'application/pics-rules'.
  369. 'prt' -> 'chemical/x-ncbi-asn1-ascii'.
  370. 'ps' -> 'application/postscript'.
  371. 'psd' -> 'image/x-photoshop'.
  372. 'psp' -> 'text/x-psp'.
  373. 'py' -> 'text/x-python'.
  374. 'pyc' -> 'application/x-python-code'.
  375. 'pyo' -> 'application/x-python-code'.
  376. 'qt' -> 'video/quicktime'.
  377. 'qtl' -> 'application/x-quicktimeplayer'.
  378. 'ra' -> 'audio/x-realaudio'.
  379. 'ram' -> 'audio/x-pn-realaudio'.
  380. 'rar' -> 'application/rar'.
  381. 'ras' -> 'image/x-cmu-raster'.
  382. 'rd' -> 'chemical/x-mdl-rdfile'.
  383. 'rdf' -> 'application/rdf+xml'.
  384. 'rgb' -> 'image/x-rgb'.
  385. 'rm' -> 'audio/x-pn-realaudio'.
  386. 'roff' -> 'application/x-troff'.
  387. 'ros' -> 'chemical/x-rosdal'.
  388. 'rpm' -> 'application/x-redhat-package-manager'.
  389. 'rss' -> 'application/rss+xml'.
  390. 'rtf' -> 'text/rtf'.
  391. 'rtx' -> 'text/richtext'.
  392. 'rxn' -> 'chemical/x-mdl-rxnfile'.
  393. 'sct' -> 'text/scriptlet'.
  394. 'sd' -> 'chemical/x-mdl-sdfile'.
  395. 'sd2' -> 'audio/x-sd2'.
  396. 'sda' -> 'application/vnd.stardivision.draw'.
  397. 'sdc' -> 'application/vnd.stardivision.calc'.
  398. 'sdd' -> 'application/vnd.stardivision.impress'.
  399. 'sdf' -> 'chemical/x-mdl-sdfile'.
  400. 'sdp' -> 'application/vnd.stardivision.impress'.
  401. 'sdw' -> 'application/vnd.stardivision.writer'.
  402. 'ser' -> 'application/java-serialized-object'.
  403. 'sgf' -> 'application/x-go-sgf'.
  404. 'sgl' -> 'application/vnd.stardivision.writer-global'.
  405. 'sh' -> 'text/x-sh'.
  406. 'shar' -> 'application/x-shar'.
  407. 'shtml' -> 'text/html'.
  408. 'sid' -> 'audio/prs.sid'.
  409. 'sik' -> 'application/x-trash'.
  410. 'silo' -> 'model/mesh'.
  411. 'sis' -> 'application/vnd.symbian.install'.
  412. 'sit' -> 'application/x-stuffit'.
  413. 'skd' -> 'application/x-koan'.
  414. 'skm' -> 'application/x-koan'.
  415. 'skp' -> 'application/x-koan'.
  416. 'skt' -> 'application/x-koan'.
  417. 'smf' -> 'application/vnd.stardivision.math'.
  418. 'smi' -> 'application/smil'.
  419. 'smil' -> 'application/smil'.
  420. 'snd' -> 'audio/basic'.
  421. 'spc' -> 'chemical/x-galactic-spc'.
  422. 'spl' -> 'application/x-futuresplash'.
  423. 'src' -> 'application/x-wais-source'.
  424. 'stc' -> 'application/vnd.sun.xml.calc.template'.
  425. 'std' -> 'application/vnd.sun.xml.draw.template'.
  426. 'sti' -> 'application/vnd.sun.xml.impress.template'.
  427. 'stl' -> 'application/vnd.ms-pki.stl'.
  428. 'stw' -> 'application/vnd.sun.xml.writer.template'.
  429. 'sty' -> 'text/x-tex'.
  430. 'sv4cpio' -> 'application/x-sv4cpio'.
  431. 'sv4crc' -> 'application/x-sv4crc'.
  432. 'svg' -> 'image/svg+xml'.
  433. 'svgz' -> 'image/svg+xml'.
  434. 'sw' -> 'chemical/x-swissprot'.
  435. 'swf' -> 'application/x-shockwave-flash'.
  436. 'swfl' -> 'application/x-shockwave-flash'.
  437. 'sxc' -> 'application/vnd.sun.xml.calc'.
  438. 'sxd' -> 'application/vnd.sun.xml.draw'.
  439. 'sxg' -> 'application/vnd.sun.xml.writer.global'.
  440. 'sxi' -> 'application/vnd.sun.xml.impress'.
  441. 'sxm' -> 'application/vnd.sun.xml.math'.
  442. 'sxw' -> 'application/vnd.sun.xml.writer'.
  443. 't' -> 'application/x-troff'.
  444. 'tar' -> 'application/x-tar'.
  445. 'taz' -> 'application/x-gtar'.
  446. 'tcl' -> 'text/x-tcl'.
  447. 'tex' -> 'text/x-tex'.
  448. 'texi' -> 'application/x-texinfo'.
  449. 'texinfo' -> 'application/x-texinfo'.
  450. 'text' -> 'text/plain'.
  451. 'tgf' -> 'chemical/x-mdl-tgf'.
  452. 'tgz' -> 'application/x-gtar'.
  453. 'tif' -> 'image/tiff'.
  454. 'tiff' -> 'image/tiff'.
  455. 'tk' -> 'text/x-tcl'.
  456. 'tm' -> 'text/texmacs'.
  457. 'torrent' -> 'application/x-bittorrent'.
  458. 'tr' -> 'application/x-troff'.
  459. 'ts' -> 'text/texmacs'.
  460. 'tsp' -> 'application/dsptype'.
  461. 'tsv' -> 'text/tab-separated-values'.
  462. 'txt' -> 'text/plain'.
  463. 'udeb' -> 'application/x-debian-package'.
  464. 'uls' -> 'text/iuls'.
  465. 'ustar' -> 'application/x-ustar'.
  466. 'val' -> 'chemical/x-ncbi-asn1-binary'.
  467. 'vcd' -> 'application/x-cdlink'.
  468. 'vcf' -> 'text/x-vcard'.
  469. 'vcs' -> 'text/x-vcalendar'.
  470. 'vmd' -> 'chemical/x-vmd'.
  471. 'vms' -> 'chemical/x-vamas-iso14976'.
  472. 'vor' -> 'application/vnd.stardivision.writer'.
  473. 'vrm' -> 'x-world/x-vrml'.
  474. 'vrml' -> 'x-world/x-vrml'.
  475. 'vsd' -> 'application/vnd.visio'.
  476. 'wad' -> 'application/x-doom'.
  477. 'wav' -> 'audio/x-wav'.
  478. 'wax' -> 'audio/x-ms-wax'.
  479. 'wbmp' -> 'image/vnd.wap.wbmp'.
  480. 'wbxml' -> 'application/vnd.wap.wbxml'.
  481. 'wk' -> 'application/x-123'.
  482. 'wm' -> 'video/x-ms-wm'.
  483. 'wma' -> 'audio/x-ms-wma'.
  484. 'wmd' -> 'application/x-ms-wmd'.
  485. 'wml' -> 'text/vnd.wap.wml'.
  486. 'wmlc' -> 'application/vnd.wap.wmlc'.
  487. 'wmls' -> 'text/vnd.wap.wmlscript'.
  488. 'wmlsc' -> 'application/vnd.wap.wmlscriptc'.
  489. 'wmv' -> 'video/x-ms-wmv'.
  490. 'wmx' -> 'video/x-ms-wmx'.
  491. 'wmz' -> 'application/x-ms-wmz'.
  492. 'wp5' -> 'application/wordperfect5.1'.
  493. 'wpd' -> 'application/wordperfect'.
  494. 'wrl' -> 'x-world/x-vrml'.
  495. 'wsc' -> 'text/scriptlet'.
  496. 'wvx' -> 'video/x-ms-wvx'.
  497. 'wz' -> 'application/x-wingz'.
  498. 'xbm' -> 'image/x-xbitmap'.
  499. 'xcf' -> 'application/x-xcf'.
  500. 'xht' -> 'application/xhtml+xml'.
  501. 'xhtml' -> 'application/xhtml+xml'.
  502. 'xlb' -> 'application/vnd.ms-excel'.
  503. 'xls' -> 'application/vnd.ms-excel'.
  504. 'xlt' -> 'application/vnd.ms-excel'.
  505. 'xml' -> 'application/xml'.
  506. 'xpi' -> 'application/x-xpinstall'.
  507. 'xpm' -> 'image/x-xpixmap'.
  508. 'xsl' -> 'application/xml'.
  509. 'xtel' -> 'chemical/x-xtel'.
  510. 'xul' -> 'application/vnd.mozilla.xul+xml'.
  511. 'xwd' -> 'image/x-xwindowdump'.
  512. 'xyz' -> 'chemical/x-xyz'.
  513. 'zip' -> 'application/zip'.
  514. 'zmt' -> 'chemical/x-mopac-input'.
  515. '~' -> 'application/x-trash'
  516. }
  517. !
  518. mimeTypes
  519. ^mimeTypes ifNil: [mimeTypes := self defaultMimeTypes]
  520. !
  521. mimeTypeFor: aString
  522. ^self mimeTypes at: (aString replace: '.*[\.]' with: '') ifAbsent: ['text/plain']
  523. ! !
  524. !FileServer class methodsFor: 'initialization'!
  525. main
  526. ^self new startOn: self port
  527. ! !