<div dir="ltr">Hello list,<div><br></div><div>I'm trying to get Clack (<a href="http://clacklisp.org/">http://clacklisp.org/</a>) 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).</div><div><br></div><div>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:</div><div><br></div><div><div>(defconstant +latin-1+</div><div>  (make-external-format :latin1 :eol-style :lf)</div><div>  "A FLEXI-STREAMS external format used for `faithful' input and</div><div>output of binary data (via hunchentoot/specials.lisp).")</div><div><br></div></div><div><div><div>(defun make-stream-for-request (req content-length)</div><div>  "Construct a Lisp input flexi-stream from the binary stream provided</div><div>by the HTTPServletRequest. Set the bound of the stream to the value of</div><div>the Content-Length header, if any."</div><div>  (let* ((java-stream (#"getInputStream" req))</div><div><span class="" style="white-space:pre">       </span> (lisp-stream (jss:new :|lisp.Stream|</div><div><span class="" style="white-space:pre">                      </span>       (jss:get-java-field :|lisp.Symbol| "SYSTEM_STREAM") ; structureClass</div><div><span class="" style="white-space:pre">                   </span>       java-stream</div><div><span class="" style="white-space:pre">                      </span>       '(unsigned-byte 8)))) ; elementType</div><div>    (make-flexi-stream lisp-stream</div><div><span class="" style="white-space:pre">               </span>       :external-format +latin-1+</div><div><span class="" style="white-space:pre">               </span>       :bound content-length)))</div></div></div><div><br></div><div><div><div>We agreed that there's not much documentation around this, hence this email.</div><div><br></div><div>Cheers,</div><div><br></div><div>John :^P</div><div>-- <br>John Pallister<br><a href="mailto:john@johnp.net" target="_blank">john@johnp.net</a><br><a href="mailto:john@synchromesh.com" target="_blank">john@synchromesh.com</a></div></div>
</div></div>