-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjfilesrc.ijs
72 lines (65 loc) · 2.14 KB
/
jfilesrc.ijs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
NB. JHS - file source stuff - favicon.ico ...
coclass'jfilesrc'
coinsert'jhs'
NB. serves .htm .js etc pages from anywhere
NB. possible security issues! careful on allowing other suffixes!
jev_get=: 3 : 0
if. 0=nc<'gets_jhs_' do. gets_jhs_=: gets_jhs_,y,LF end.
if. y-:'favicon.ico' do. favicon 0 return. end.
if. (-.IFWIN)*.'usr/share/'-:10{.y do. y=. '/',y end. NB. gnuplot kludge
y=. jpath y
d=. fread y
if. _1=d do. echo 'get file does not exist: ',y return. end.
NB. Firefox 8 requires a response header
if. ('.htm'-:_4{.y)+.'.html'-:_5{.y do. htmlresponse d,~fsrchead rplc '<TYPE>';'text/html' return. end.
if. (#mimetypes) > i=. ({:"1 mimetypes) i. <@tolower@}.(}.~ i:&'.') y do.
t=. i{:: {."1 mimetypes
else. echo 'will not get file ',y return. end.
t gsrcf d
)
NB. common mime types
mimetypes=: <;._1@(' '&,)@deb;._2 (0 : 0)
application/javascript js
application/javascript map
application/msword doc
application/msword docx
application/pdf pdf
application/postscript eps
application/postscript ps
application/rtf rtf
application/vnd.ms-excel xls
application/vnd.ms-excel xlsx
application/x-gnumeric gnumeric
application/x-gtar-compressed tgz
application/x-sc sc
application/zip zip
audio/mp3 mp3
image/gif gif
image/jpeg jpeg
image/jpeg jpg
image/png png
image/tiff tif
image/tiff tiff
image/x-icon ico
image/x-ms-bmp bmp
text/css css
text/csv csv
text/html htm
text/html html
text/plain text
text/plain txt
video/x-ms-wmv wmv
video/x-msvideo avi
)
favicon=: 3 : 0
htmlresponse htmlfav,1!:1 <jpath'~addons/ide/jhs/favicon.ico'
)
htmlfav=: toCRLF 0 : 0
HTTP/1.1 200 OK
Server: J
Accept-Ranges: bytes
Content-Length: 1150
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: image/x-icon
)