Power Up SBCL CGI
I wrote a simple CGI script with SBCL in this article. But, I would like to include the host information into the http response. Then, I modified a little bit from above article implementation. Here is a new version.
#!/usr/bin/sbcl --script (defun get-timestamp-as-string () (let ((day-names '("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun")) (mon-names '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))) (labels ((pad (n) (if (< (length (write-to-string n)) 2) (concatenate 'string "0" (write-to-string n)) (write-to-string n)))) (multiple-value-bind (second minute hour date month year day-of-week dst-p time-zone) (decode-universal-time (get-universal-time)) (concatenate 'string (nth (- day-of-week 1) day-names) " " (nth (- month 1) mon-names) " " (pad date) " " (pad hour) ":" (pad minute) ":" (pad second) " " "GMT" (write-to-string time-zone) " " (write-to-string year)))))) (format t "Content-Type:text/plain~%~%") (format t "~A ~A~%" (get-timestamp-as-string) (machine-instance))
SBCL can get a hostname with machine-instance function. This CGI response is like below.
# curl http://localhost/cgi-bin/default.l Fri May 30 19:34:52 GMT-9 2014 myhost #