lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Oct 10, 2012 at 3:11 PM, Petite Abeille
<petite.abeille@gmail.com> wrote:
>
> On Oct 10, 2012, at 8:12 PM, Tim Caswell <tim@creationix.com> wrote:
>
>> https://github.com/creationix/moonslice-luv
>> https://github.com/creationix/luv
>> https://github.com/creationix/lhttp_parser
>
> Nice.
>
> One quick thing though:
>
> https://github.com/creationix/moonslice-luv/blob/master/autoheaders.lua#L49
>
> At first glance. it doesn't look like your connection keep-alive logic is correct [1]… i.e. try your server with a plain HTT/1.0 client and see what happen… on the other hand, perhaps I misread it.

I could have it wrong.  I still don't fully understand keepalive.
I've love to get feedback from people who understand it better.  The
module is a sample more than anything, but I do intend for it to be
production quality.  http://luvit.io/ is running on moonslice on top
of luvit right now.

>
> Also, it's perhaps unfortunate that your API doesn't seem to support a plain function as valid body producer. Perfect for chunking in conjunction with coroutine. But then again, perhaps I just missed it.

It supports either a string or a readable stream.  A readable stream
is pretty simple.  It's any table that has a :read()(callback) method.

What would a "plain function as body" look like?  If the data is
available syncronously then just use a string, if you need to stream
over time, use a stream.  The simple stream API I designed supports
"backpressure" so you don't get into situations when you're reading a
large file from a local disk and writing to some slow mobile client
and end up buffering everything in ram.  The simplest interface I
could think of is readFunction(callback(err, data)), but I find a
table with a continuable version of the read is easier to work with.
For example using coroutines, piping from a file to a socket is as
simple as:

    repeat
      local chunk = await(input:read())
      await(outout:write(chunk))
    while chunk



>
> While on the subject of chunking, not sure about your chunk terminator… why 3 time CRLF? But then again, perhaps I'm missing the bigger picture and just being hasty :)

That's how I read the spec, and it seems to work.  My clients (curl
and various browsers) seem to like it.  There is a change I misread
the spec though.

>
> https://github.com/creationix/moonslice-luv/blob/master/autoheaders.lua#L44
>
> [1] http://en.wikipedia.org/wiki/HTTP_persistent_connection
>
>