John, don't forget to publish your results when you have clack working with ABCL
š
19.11.2015, 01:24, "John Pallister" <john@synchromesh.com>:
Hello list,
š
I'm trying to get Clack (http://clacklisp.org/) running on Google App Engine which means doing a Java Servlets back-end. Clack expects a :RAW-BODY request header that is an input stream, and the HTTPServletRequest object I receive from the Jetty web server inherits a getReader() method (for a character stream) and a getInputStream() method (for a binary stream).
š
Looking at the "reference implementation" (i.e. Hunchentoot), it creates a FLEXI-STREAM so that any HTTP "Content-Length" header can be used to set the bound on the stream. So based on that, and an IRC chat with Mark E., and some scratch code, I've come up with this to create a FLEXI-STREAM from the HTTPServletRequest:
š
(defconstant +latin-1+
š (make-external-format :latin1 :eol-style :lf)
š "A FLEXI-STREAMS external format used for `faithful' input and
output of binary data (via hunchentoot/specials.lisp).")
š
(defun make-stream-for-request (req content-length)
š "Construct a Lisp input flexi-stream from the binary stream provided
by the HTTPServletRequest. Set the bound of the stream to the value of
the Content-Length header, if any."
š (let* ((java-stream (#"getInputStream" req))
(lisp-stream (jss:new :|lisp.Stream|
š š š (jss:get-java-field :|lisp.Symbol| "SYSTEM_STREAM") ; structureClass
š š š java-stream
š š š '(unsigned-byte 8)))) ; elementType
š š (make-flexi-stream lisp-stream
š š š :external-format +latin-1+
š š š :bound content-length)))
š
We agreed that there's not much documentation around this, hence this email.
š
Cheers,
š
John :^P
--
John Pallister
john@johnp.net
john@synchromesh.com