On Fri, 8 Jun 2007 11:19:43 -0400, "Andrei Stebakov" lispercat@gmail.com wrote:
Recently I've been thinking how to make http-request upload a file, but not from the hard drive but from a function which can produce (or write to a) stream. Let's say I want to create an image with cl-gd but instead of writing the image to the file and then creating the http-request with a pathname of the file I can pass a (lambda (stream) (cl-gd-create-image stream your param1 param2)) in place of the pathname parameter. Or a stream which already has the file data. I was trying to do it using :content :continuation but found it too difficult, maybe I missed other ways.
You could have passed a function designator to :CONTENT. That's a bit easier than to use :CONTINUATION, but you'd still have to create the form-data wrappers yourself.
Anyway, I created a patch with very minimal changes to the make-form-data-function function which allows to do so. Also I found that I set *header-stream* to not nil, I was missing the debug output produced by the character (character only) stream from make-form-data-function which basically shows all the parameters we are sending. I added the primitive support for this based on make-broadcast-stream. Here I attach the patch for your kind consideration.
The general idea is fine with me. As for the patch I have a few things I don't like:
1. Now that the value can be more than a pathname, the variable shouldn't be called PATHNAME anymore.
2. The docstring for HTTP-REQUEST and the HTML documentation need to be updated as well. See also
3. The patch contains TAB characters.
4. Where you have *STANDARD-OUTPUT*, you probably want to have *HEADER-STREAM*.
5. But I generally don't really like this part anyway. The stream is called *HEADER-STREAM* because the /headers/ are supposed to be sent there. Sending /parts/ of the form-data there as well might be useful in a few cases but it seems like a fortuitous choice to me.
Thanks, Edi.