[hunchentoot-devel] hunchentoot-cgi and the new hunchentoot regime

Cyrus Harmon ch-tbnl at bobobeach.com
Tue Jul 22 15:47:56 UTC 2008


Hans,

Yes, my original code was a "proof of concept" that I didn't need to  
hack up send-output to make this is work. Your version is much better.

thanks!

Cyrus

On Jul 21, 2008, at 10:33 PM, Hans Hübner wrote:

> Cyrus,
>
> in the code sample below, is it your intention to discard all headers
> sent by the CGI program?  If not, I'd suggest that you just add them
> all to the list of outgoing headers.  Also, you may want to use a
> COPY-STREAM function (like
> http://bknr.net/trac/browser/trunk/bknr/datastore/src/utils/utils.lisp#L189)
> instead of copying the data character wise for efficiency and
> readability.
>
> (let* ((process (sb-ext::run-program path nil
>                                     :output :stream
>                                     :environment env))
>       (in (sb-ext:process-output process)))
>  (loop for line = (chung:read-line* in)
>       until (equal line "")
>       do (destructuring-bind (key val)
>              (ppcre:split ":\\s*" line)
>            (setf (hunchentoot:header-out key) val)))
>  (copy-stream in (flexi-streams:make-flexi-stream
>                   (tbnl:send-headers)
>                   :external-format tbnl::+latin-1+)
>               :element-type 'character))
>
> -Hans
>
> On Tue, Jul 22, 2008 at 04:04, Cyrus Harmon <ch-tbnl at bobobeach.com>  
> wrote:
>> Falling squarely in the more than one way to skin a cat, perhaps  
>> it's easier
>> to just read off the CGI headers and DTRT WRT to those headers and  
>> then send
>> the output of the CGI to the tbnl output-stream.
>>
>> (let* ((process (sb-ext::run-program path nil
>>                                          :output :stream
>>                                          :environment env))
>>            (in (sb-ext:process-output process)))
>>       (let ((headers
>>              (loop for line = (chunga:read-line* in)
>>                 until (equal line "")
>>                 collect (destructuring-bind
>>                               (key val)
>>                             (ppcre:split ": " line)
>>                           (cons (chunga:as-keyword key) val)))))
>>         (let ((type-cons (assoc :content-type headers)))
>>           (when type-cons
>>             (setf (tbnl:content-type)
>>                   (cdr type-cons)))))
>>       (let ((out (flexi-streams:make-flexi-stream
>>                   (tbnl:send-headers)
>>                   :external-format tbnl::+latin-1+)))
>>         (do ((c (read-char in) (read-char in)))
>>             ((eq c 'eof))
>>           (write-char c out))))
>>
>> This works well enough for the git CGI interface to sit behind (an  
>> unhacked)
>> hunchentoot and hunchentoot-cgi as can be seen here:
>>
>> http://git.cyrusharmon.org/cgi-bin/gitweb.cgi?p=hunchentoot-cgi.git
>>
>> thanks for prodding me to think about this some more...
>>
>> cyrus
>>
>>
>> On Jul 20, 2008, at 11:44 PM, Edi Weitz wrote:
>>
>>> On Mon, 21 Jul 2008 07:54:51 +0200, "Hans Hübner" <hans at huebner.org>
>>> wrote:
>>>
>>>> Why not make the flag to suppress sending the content type and
>>>> terminating the header be an argument to START-OUTPUT?  I don't
>>>> think that adding more special variables for no good reason would  
>>>> be
>>>> so nice.  It may just be me, though.
>>>
>>> Fine with me.
>>>
>>> What's so special about the content type, though?  Do you actually
>>> want /any/ headers to be sent or any processing to be done?
>>> _______________________________________________
>>> tbnl-devel site list
>>> tbnl-devel at common-lisp.net
>>> http://common-lisp.net/mailman/listinfo/tbnl-devel
>>
>> _______________________________________________
>> tbnl-devel site list
>> tbnl-devel at common-lisp.net
>> http://common-lisp.net/mailman/listinfo/tbnl-devel
>>
> _______________________________________________
> tbnl-devel site list
> tbnl-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/tbnl-devel




More information about the Tbnl-devel mailing list