fukamachi / woo

A fast non-blocking HTTP server on top of libev
http://ultra.wikia.com/wiki/Woo_(kaiju)
MIT License
1.28k stars 98 forks source link

Outputting stream of data in a handler doesn't work on woo #46

Closed a13x closed 7 years ago

a13x commented 8 years ago

I wrote a simple demo app with ningle and clack running on woo server serving PNG images (gist: here). When I output the stream of created image directly in the handler, the server fails on woo with the following error:

debugger invoked on a FAST-HTTP.ERROR:CB-MESSAGE-COMPLETE in thread

<THREAD "clack-handler-woo" RUNNING {1006C9B2B3}>:

Callback Error: the message-complete callback failed The value #(137 80 78 71 13 10 26 10 0 0 0 13 ...) is not of type (SIMPLE-ARRAY (UNSIGNED-BYTE 8) (*)).

The code works fine on hunchentoot. The only way i figured this working is to coerce a stream into a simple-array: (coerce output '(simple-array (unsigned-byte 8) (*))

That just looks weird to me - woo should be able to handle outputting to stream so it seems to me I'm doing something wrong.

fukamachi commented 8 years ago

If serving an PNG file is what you want to do, just return a pathname at the body position (the third value of the response list).

a13x commented 8 years ago

I'm generating a PNG image on the fly (as shown in the gist) so that's not an option :)

fukamachi commented 8 years ago

Well, first of all, your code doesn't stream the content. It creates a binary sequence and returns it. I don't know where the with-output-to-sequence from and what is the type of its response, but it may work if you coerce it to a simple-vector.

See Lack's README what is valid for the body.

The response body must be returned from the application in one of three formats, a list of strings, a byte vectors, or a pathname. https://github.com/fukamachi/lack#normal-response

And see this for getting the way to actually stream it is: https://github.com/fukamachi/lack#delayed-response-and-streaming-body

a13x commented 8 years ago

Apologies for using the term streaming :) (with-output-to-sequence) comes from babel-streams and I use it to save png image to a binary sequence (using vecto:save-png-stream) so by streaming I meant streaming into a sequence and returning it.

The output of a with-output-to-sequence is a (VECTOR (UNSIGNED-BYTE 8) as specified in element-type.

Even if I call babel:octets-to-string to convert the vector to a string and return it, woo complains (with the same error as above).

The same code (in the gist) works just fine if I use :server 'hunchentoot when starting clack, so I believe the issue lies in woo.

a13x commented 8 years ago

Since there's no replies, I guess I'll just dig deeper into woo code and try to fix it myself. From the perspective of clack, it looks like a bug or missing functionality in woo, since code without coercion works fine with other servers (hunchentoot and wookie).

fukamachi commented 7 years ago

v0.11.4 accepts vectors, not only (unsigned-byte 8), as the response body.