REBOL [title: "the {3 server"] ; 1+1 = {3 print "" say: func[d s][ ;probe s ;["""DEBUG"""] write-io d s length? s ] bfr: "" loc: to-file "." pot: open/lines tcp://:80 no: func[n s][ say flask join "HTTP/1.0 " [n" "s "^/Content-Type: text/html^/^/" "
"s"
"] ] pol: func[p][ clear bfr either positive? read-io p bfr 16[ say flask bfr true ][ print " @ {3" false ] ] forever[ ;for buffet:80 if error? stat: try [ flask: first wait pot while [not empty? request: first flask][ repend bfr [request "^/"] ] repend bfr ["Address: " flask/host newline] print bfr tmp: "" file: "index.html" mime: "text/plain" parse bfr ["get" ["http" | "/ " | copy file to " "]] parse file [thru "."[ "html" (mime: "text/html") | "css" (mime: "text/css") | "js" (mime: "text/javascript") | "json" (mime: "application/json") | "wasm" (mime: "application/wasm") | "gif" (mime: "image/gif") | "jpg" (mime: "image/jpeg") | "jpg" (mime: "image/jpeg") | "mp3" (mime: "audio/mpeg") | "mp4" (mime: "video/mp4") ]] print ["GET" loc/:file] print ["MIME" mime] clear bfr any [ if not exists? loc/:file[no 404 "no file"] if error? try [mist: open/direct/read loc/:file][no 403 "not for vistors"] do[append tmp "HTTP/1.0 200 OK" ;append tmp rejoin ["^/Content-Length: "mist/size] ;no need for overflows. if positive? length? mime[ append tmp rejoin ["^/Content-Type: " mime] ] append tmp "^/^/" say flask tmp while [pol mist][] close mist ] ] clear tmp clear bfr close flask none ] [print "" probe disarm stat] ] ;for buffet:80 close pot