FileServer.st 17 KB

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