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