HeadlinesBriefing favicon HeadlinesBriefing.com

Sula: Gemini Server in Scryer Prolog

Hacker News •
×

Sula is a Gemini protocol server implemented in Scryer Prolog. It requires a patched version of Scryer Prolog, available on a specific branch, which includes several crucial modifications. These patches enable efficient binary file streaming via a native '$copy_stream'/2 builtin, prevent infinite loops in stream reading with library(pio)’s buffer_prepare_for_n/5, and allow for graceful shutdown by catching SIGINT exceptions.

Furthermore, the patched Scryer includes a port to rustls for TLS support and modifies tls_server_negotiate to handle optional client certificates. The server is launched using a polyglot script that invokes Scryer Prolog with specific entry goals. Configuration is managed through command-line options, including address, hostname, content directory, and certificate directory.

Sula features TLS via rustls, PKCS#12 identity files, and robust hostname verification using 'openssl x509'. Content negotiation is handled by extension, parsing '/etc/mime.types' and adding 'text/gemini' for '.gmi' files. Responses are efficiently served, with binary data streamed natively to avoid Prolog heap overhead. Error handling is per-connection, logging TLS handshake failures and client disconnects while re-throwing other errors. Graceful shutdown on SIGINT is supported through the patched Scryer.

Planned features include support for client certificates, CGI script execution, rate limiting, and virtual hosting. The project structure includes modules for configuration, certificate handling, MIME types, request processing, and logging.