retroforth/example/shared.retro
crc 848ba7303b use .retro instead of .forth in examples
FossilOrigin-Name: b5feea667d30aac255d1cfca61fed355d438d2ce6021677f1e53af6302b15eee
2019-08-20 18:46:40 +00:00

27 lines
873 B
Forth
Executable file

#!/usr/bin/env retro
This is a little server for the pastebin. Use it with inetd or similar:
gopher stream tcp nowait/6/30/2 nope /home/crc/retro/example/shared.forth
http stream tcp nowait/6/30/2 nope /home/crc/retro/example/shared.forth
It understands HTTP and Gopher, so can work for either. Use it with the
`share.forth` tool.
~~~
s:get 'REQUEST s:const
:http? REQUEST #0 #3 s:substr 'GET s:eq? ;
:extract REQUEST #32 s:tokenize #2 + fetch ;
:ok 'HTTP/1.0_200_OK\n s:format s:put ;
:mime 'Content-type:_text/plain\n\n s:format s:put ;
:file '/home/crc/public%s s:format ;
:read here swap file:slurp here ;
:missing drop 'Selector_not_found. ;
:get dup file:exists? [ read ] if; missing ;
:http ok mime extract file get s:put ;
:gopher REQUEST file get s:put ;
:serve http? [ http ] if; gopher ;
serve
~~~