1
0

FileServer.st 18 KB

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