diff --git a/LICENSE b/LICENSE index c7ffc1a..8e259ad 100644 --- a/LICENSE +++ b/LICENSE @@ -1 +1,8 @@ -"THE BEER-WARE LICENSE" (Revision 42): wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. kiefac + * ---------------------------------------------------------------------------- + */ diff --git a/rebound.rkt b/rebound.rkt new file mode 100644 index 0000000..87d6190 --- /dev/null +++ b/rebound.rkt @@ -0,0 +1,60 @@ +#lang racket/gui +(require openssl) + +(define port 1965) +(define target "geminiprotocol.net") +(define request "gemini://geminiprotocol.net/index.gmi\r\n") + +(define-values (in out) (ssl-connect/enable-break target port)) +(file-stream-buffer-mode out 'none) + +(display request out) +(flush-output out) + +(let* ([response-head (read-line in)] + [status (string->number (substring response-head 0 2))] + [status-first (quotient status 10)] + [status-last (modulo status 10)] + [info (if (> (string-length response-head) 2) + (string-trim (substring response-head 2)) + "[none given]")]) + (case status-first + [(1) (case status-last + [(1) (display "requesting sensitive input, ")] + [else (display "requesting normal input, ")]) + (displayln (~a "input prompt: " info))] + + [(2) (case info + [("text/gemini" "text/plain") (displayln (port->string in))] + [else (displayln (~a "requested file is of unhandled mimetype: " info))])] + + [(3) (case status-last + [(1) (display "permanently")] + [else (display "temporarily")]) + (displayln (~a " redirecting to: " info))] + + [(4) (display "temporary failure, reason: ") + (case status-last + [(1) (display "server unavailable")] + [(2) (display "cgi error")] + [(3) (display "proxy error")] + [(4) (display "SLOW DOWN")] + [else (display "unspecified")]) + (displayln (~a "; error message: " info))] + + [(5) (display "permanent failure, reason: ") + (case status-last + [(1) (display "file not found")] + [(2) (display "gone")] + [(3) (display "proxy request refused")] + [(9) (display "bad request")] + [else (display "unspecified")]) + (displayln (~a "; error message: " info))] + + [(6) (display "client certificate ") + (case status-last + [(1) (display "not authorized")] + [(2) (display "not valid")] + [else (display "required")]) + (displayln (~a "; error message: " info))] + )) \ No newline at end of file