scheme-libraries/retropikzel/cgi
retropikzel 936e34a373 Moving libraries 2025-10-29 16:53:08 +02:00
..
README.md Moving libraries 2025-10-29 16:53:08 +02:00
VERSION Moving libraries 2025-10-29 16:53:08 +02:00
test.scm Moving libraries 2025-10-29 16:53:08 +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. Also checkout https://git.sr.ht/~retropikzel/scheme-php.

Project

Repository

Issue tracker

Caveats

  • Works only on unix as it reads from /dev/fd/0 and /dev/random.

Buggy on implementations

  • Does not work with mit-scheme
    • For some reason mit-scheme exits when it reads eof-object from standard input
  • STklos
    • No output for some reason

How to use

Example using Gauche in Docker.

lighttpd.conf:

server.document-root = "/workdir"
server.port = 3000
server.modules += ("mod_cgi", "mod_dirlisting")
cgi.assign = (".scm"  => "/usr/bin/scheme-script")
dir-listing.activate = "enable"

Dockerfile:

FROM schemers/gauche
RUN apt-get update && apt-get install -y --no-install-recommends lighttpd
WORKDIR /workdir
EXPOSE 3000
COPY lighttpd.conf /lighttpd.conf
RUN echo "#!/bin/sh" > /usr/bin/scheme-script
RUN echo "exec gosh -r7 -I ./snow \$@" >> /usr/bin/scheme-script
RUN chmod +x /usr/bin/scheme-script
ENTRYPOINT ["/usr/sbin/lighttpd", "-D", "-f", "/lighttpd.conf"]

hello.scm:

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

(display "Content-type: text/html")
(display "\r\n")
(display "\r\n")
(display "Hello")
(display "</br>")

(display "Request: ")
(write (get-request))
(display "</br>")
(cgi-exit)

Run:

docker build . --tag=scheme-cgi
docker run -it -v ${PWD}:/workdir -p 3000:3000 scheme-cgi

Then navigate with your browser to http://127.0.0.1:3000

Documentation

Reference

get-request

Returns the whole request as association list.

get-header name

Name can be symbol or a string. Returns the value of given header or #f.

get-headers

Returns association list of all headers.

get-parameter name

Name can be symbol or a string. Returns the value of given parameter or #f.

get-parameters

Returns association list of all parameters.

get-cookie name

Returns the value of given cookie or #f if.

get-cookies

Returns association list of all cookies.

get-file filename

Filename is a symbol or a string. Returns the path of given file from files or #f.

Uploaded files are stored in /tmp, with randomly generated prefix on their name. They are not deleted unless cgi-exit is called. Use move-file to move them into preferred location.

get-files

Returns association list of all files.

move-file from to

Moves a file from from path to to path.

get-body

Returns the request body.

cgi-exit
cgi-exit code

Does necessary cleanup and exits the script. Code is a number, if it is given then that is used as exit code.

Environment variables

SCHEME_CGI_TMP_PATH

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