REBOL [ Title: "Micro Web Server" Date: 24-June-1999 Purpose: "A web server for HTML and images only" ] web-dir: %web-pages listen-port: open/lines tcp://:80 ; port used for web connections errors: [ 400 "Forbidden" "No permission to access:" 404 "Not Found" "File was not found:" ] send-error: function [err-num file] [err] [ err: find errors err-num insert http-port form ["HTTP/1.0" err-num err/2 "^/Content-type: text/html^/^/" <HTML> <TITLE> err/2 </TITLE> "<BODY><H1>SERVER ERROR</H1><P>REBOL Webserver Error:" err/3 file newline <P> </BODY> </HTML> ] ] send-page: func [data mime] [ insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"] write-io http-port data length? data ] while [on] [ http-port: first wait listen-port request: first http-port file: "index.html" mime: "text/plain" parse request ["get" ["http" | "/ " | copy file to " "]] parse file [thru "." [ "html" (mime: "text/html") | "gif" (mime: "image/gif") | "jpg" (mime: "image/jpeg") ] ] ] any [ if not exists? web-dir/:file [send-error 404 file] if error? try [data: read/binary web-dir/:file] [send-error 400 file] send-page data mime ] close http-port ]
Script Junkie | REBOL Bots
Over the past two decades, my search for the perfect scripting language led me to work with companies such as HP, Amiga, and Apple. In that time, I investigated more than 50 different languages, from Ada to C, from Pascal to Lisp. I wanted a language that was very simple and readable with almost no syntax, yet very flexible with a wide degree of expressive freedom.Related Reading
More Insights
INFO-LINK
To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy. | |