36877ecffd/forthlets/httpd/httpd-0.9.retro

User picture

Commiter: Charles Childers

Author: Charles Childers

Revision: 36877ecffd


File Size: 1.61 KB

(March 13, 2010 16:25 UTC) About 2 years ago

rename httpd to httpd-0.9

 
Show/hide line numbers
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( HTTP/0.9 Server                                           )
( Charles Childers, 2010                                    )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( See http://www.w3.org/Protocols/HTTP/AsImplemented.html   )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( This is a really simple web server intended to show how   )
( sockets and the net/server library can be used.           )
(                                                           )
( Some features:                                            )
(  - 7 words; under 2k cells when compiled                  )
(  - serve actual html files                                )
(  - log requests to terminal window                        )
(  - handler for 404 errors                                 )
(  - can be killed by visiting a special page               )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )

include library/net/server.retro
include library/files.retro

vocab httpd/0.9
((
  : 404    ( -a ) s" <html><body><h1>Error 404!</h1></body></html>" ;
  : GET?   ( - )
    repeat
      <get> nib s" GET" compare if <get> ." Requested: " nib type cr ;then
    again ;
  : INDEX? ( - ) nib s" /" compare if s" index.html" ;then nib 1+ ;
  : ERROR? ( - ) here @ if here ;then 404 ;
  : EXIT?  ( - ) nib s" /shutdown" compare if s" <html><body><h1>Retro-HTTPd shut down</h1></body></html>" <send> }serve cleanup bye then ;
  : SEND   ( - ) here swap slurp ERROR? <send> ;
  : start  ( - ) newServer 9812 claim repeat serve{ GET? EXIT? INDEX? SEND }serve again ;
))