scheme-libraries/retropikzel/cgi
retropikzel 62296ec2d7 cgi: Improvements on readme. New temp-file name generator 2026-08-16 13:46:31 +03:00
..
LICENSE CGI library fixes 2025-11-01 12:15:34 +02:00
README.html cgi: Improvements on readme. New temp-file name generator 2026-08-16 13:46:31 +03:00
README.md cgi: Improvements on readme. New temp-file name generator 2026-08-16 13:46:31 +03:00
VERSION Update CGI version 2026-01-17 11:05:45 +02:00
hello.scm cgi: Improvements on readme. New temp-file name generator 2026-08-16 13:46:31 +03:00
lighttp.conf cgi: Improvements on readme. New temp-file name generator 2026-08-16 13:46:31 +03:00
scheme-script cgi: Improvements on readme. New temp-file name generator 2026-08-16 13:46:31 +03:00
test.scm Update CGI version 2026-01-17 11:05:45 +02:00

README.md

R7RS Scheme library for Common Gateway Interface

If you dont know what CGI is, in short server runs your Scheme script and displays it's output as a webpage.

Installation

snow-chibi --impls=$SCHEME retropikzel.cgi

Documentation

(handle-request options thunk)

Options must be association list. Thunk must be procedure taking arguments:

  • request
    • Full request
  • headers
    • Request headers
  • parameters
    • Request parameters
      • The ?foo=bar&baz=1 part parsed
  • cookies
    • Request cookies
  • body
    • Request body
  • files
    • Request files

Whatever thunk writes to (current-output-port) is sent back as response.

Environment variables

SCM_CGI_TMPDIR

Path to where uploaded files are stored. Default is /tmp.

Usage examples

These files are shared among all examples. We will be usign Gauche for examples, but you can comment out your preferred implementation or copy just that exec line from scheme-script. (Without the #)

scheme-script:

#!/bin/sh
#exec capy --r7rs --script "$@"
#exec chibi-scheme "$@"
#exec csi -quiet -batch "$@"
#exec icyc -s "$@"
#exec gsi /home/youruser/.gambit_userlib/ "$@"
exec gosh "$@"
#exec kawa --r7rs -Dkawa.import.path=/usr/local/share/kawa/lib/*.sld "$@"
#exec loko --program "$@"
#exec mit-scheme --batch-mode --load "$@"
#exec racket -I r7rs --script "$@"
#exec sash -r7 "$@"
#exec skint "$@"
#exec stklos "$@"
#exec tr7i "$@"

hello.scm:

(import (scheme base)
        (scheme write)
        (retropikzel cgi))

(handle-request
 '()
 (lambda (request headers parameters cookies body files)
  (display "Content-type: text/html\r\n")
  (display "\r\n")
  (display "Hello</br>")
  (write request)))

Usage lighttpd example

Debian/Ubuntu/Mint:

apt-get install lighttpd

Files in any (same) directory.

lighttpd.conf:

var.basedir = env.PWD
server.document-root = basedir
server.port = 3000
server.modules += ("mod_cgi", "mod_dirlisting")
cgi.assign = (".scm"  => basedir + "/scheme-script")
dir-listing.activate = "enable"

run:

chmod +x scheme-cript
lighttpd -D -f lighttpd.conf

Then navigate with your browser to http://127.0.0.1:3000/hello.scm

Usage apache2 example

Debian/Ubuntu/Mint:

apt-get install apache2
a2enmod cgi
systemctl restart apache

Only hello.scm in /var/lib/cgi-bin/

Add shebang line as first line of hello.scm, for example:

#!/usr/local/bin/gosh

run:

chmod +x /var/lib/cgi-bin/hello.scm

Then navigate with your browser to http://127.0.0.1/cgi-bin/hello.scm

If your server does not have cgi-bin directory you can try adding it

mkdir cgi-bin

cgi-bin/.htaccess:

Options +ExecCGI
SetHandler cgi-script

That should work in any other dir too, but you propably want to make it treat only .scm files as cgi scripts.

SetHandler cgi-script "scm"