FileServer.st 17 KB

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