-- Leo's gemini proxy

-- Connecting to rwv.io:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; lang=en

Racket and gemini are awesome together


Just spend an hour playing with racket (my first) to see if I can get a gemini server up and running. I can! It's awesome!


https://racket-lang.org/


This is all it takes:


#lang racket

(require racket/string)
(require racket/port)
(require net/url-string)
(require openssl)

(define root-path "root")

(define (url-path->string p)
  (string-join (map path/param-path p) "/"))

(define listener
  (let ((listener (ssl-listen 1965)))
    (ssl-load-certificate-chain! listener "localhost.cert.pem")
    (ssl-load-private-key! listener "localhost.key.pem" #f)
    listener))

(let loop ()
  (let-values ([(in out) (ssl-accept listener)])
    (let* ((url (string->url (string-trim (read-line in))))
           (path (url-path->string (url-path url))))
      (ssl-abandon-port in)

      (display "20 text/gemini\r\n" out)
      (let ((in (open-input-file (build-path root-path path) )))
         (copy-port in out)
         (close-input-port in)))

    (ssl-abandon-port out))
  (loop))

It only responds with "20", expects everything to be gemini text and crashes when the requested file does not exists. Not yet ready for "production" but that's plenty for a language I never used. Initial commit, done.


Cheers,

R.



--

📅 2020-11-13

🏷 gemini, racket, programming

📧 hello@rwv.io

CC BY-NC-SA 4.0

-- Response ended

-- Page fetched on Tue Apr 23 18:56:14 2024