Last active
March 22, 2017 16:17
-
-
Save rgchris/e4122db19e57e577b19319270e05a3f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/ren-c | |
| Rebol [ | |
| Title: "Minimal HTTPD 404 Server" | |
| Date: 17-Mar-2017 | |
| ] | |
| sys/make-scheme [ | |
| title: "Minimal 404 Server" | |
| name: 'httpd | |
| locals: make object! [ | |
| server-port: listen-port: _ | |
| awake-client: func [event /local client] [ | |
| client: event/port | |
| switch event/type [ | |
| read [ | |
| either find client/data to-binary "^M^/^M^/" [ | |
| probe to string! client/data | |
| write client #{ | |
| 485454502F312E3020343034204E6F7420466F756E640D0A436F6E74656E742D | |
| 547970653A20746578742F706C61696E0D0A436F6E74656E742D4C656E677468 | |
| 3A20390D0A0D0A4E6F7420466F756E64 | |
| } | |
| ][ | |
| read client | |
| ] | |
| ] | |
| wrote [close client] | |
| close [close client] | |
| ] | |
| ] | |
| awake-server: func [event /local client] [ | |
| if event/type = 'accept [ | |
| client: first event/port | |
| client/awake: :awake-client | |
| read client | |
| ] | |
| ] | |
| ] | |
| actor: [ | |
| open: func [port [port!]][ | |
| port/locals: make port/scheme/locals [ | |
| server-port: :port | |
| listen-port: open rejoin [tcp://: port/spec/port-id] | |
| listen-port/awake: function [event][server-port/awake event] | |
| ] | |
| port/awake: get in port/locals 'awake-server | |
| port | |
| ] | |
| ] | |
| awake: _ | |
| ] | |
| httpd: open httpd://:8080 | |
| wait [httpd] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment