--- /dev/null
+(import (chicken io)
+ (chicken file)
+ (chicken pathname)
+ (chicken condition)
+ uri-common)
+
+(define SERVER-ROOT "public_gemini")
+(define SERVER-HOST "thelambdalab.xyz")
+
+(define (process-request request-line)
+ (condition-case
+ (let ((uri (uri-normalize-path-segments (absolute-uri request-line))))
+ (cond
+ ((not (eq? (uri-scheme uri) 'gemini))
+ (fail-permanent "Unsupported scheme."))
+ ((not (uri-host uri))
+ (fail-permanent "URL lacks host name."))
+ ((not (equal? (uri-host uri) SERVER-HOST))
+ (fail-permanent "Proxy requests forbidden."))
+ ((uri-path-relative? uri)
+ (fail-permanent "Path must be absolute."))
+ ((not (document-available? uri))
+ (fail-permanent "Document not found."))
+ (else (serve-document uri))))
+ (o (exn)
+ (print o)
+ (fail-permanent "Failed to parse URL."))))
+
+(define (fail-permanent reason)
+ (print "50 " reason "\r"))
+
+(define (document-available? uri)
+ (let ((path (apply make-pathname (cons SERVER-ROOT (cdr (uri-path uri))))))
+ (file-exists? path)))
+
+
+(define (serve-document uri)
+ (print "20 Surprise!\r"))
+
+
+(process-request "gemini://thelambdalab.xyz/../index")