Share

cl-cgi

The forum address has changed, you have been automatically redirected. Please update any bookmarks to use the new URL.

Subscribe

How I handled GET/POST

You are viewing a single message from this topic. View all messages.

  1. 2008-02-19 07:05:08 UTC
    Hey I've recently made my own cgi.lisp library here is how I did GET and POST

    (defparameter *params* (make-hash-table))

    (defun param (x)
    "Grabs from the hash based on a string"
    (gethash (intern x) *params*)
    )

    (defun split (string c)
    "Returns a list or list of lists of substrings of string
    divided by the caracter given works with recursive splittings."
    (if (listp string)
    (if (null string) nil (cons (split (car string) c) (split (cdr string) c)))
    (loop for i = 0 then (1+ j)
    as j = (position (coerce c 'character) string :start i)
    collect (subseq string i j)
    while j)
    )
    )

    ;;; get GET or POST variables and insert them into the hash
    (labels ( (getline ()
    (if (string-equal (getenv "REQUEST_METHOD") "POST")
    (read-line *standard-input* nil *standard-input*)
    (getenv "QUERY_STRING")
    )
    )
    (hash-it (l) (if (null l) nil (and (setf (gethash (intern (caar l)) *params*) (cadar l))(hash-it (cdr l)))))
    )
    (hash-it (split (split (getline) "&") "="))
    )

    To get a parameter you go (param "page") to get ?page=index for example.

    Interesting that we have done the same thing... even if mine was 7 years behind :)

< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.