• I just looked in to this, and it's a few issues.

    • First, you never do res.end() so in both cases you keep the connection to the client open and close is never called
    • You specified quite a small chunkSize. HTTP shoves data into the stream as it arrives, but because the stream is stuck shifting 32 bytes at a time (which is also really slow for file IO) data piles up and after 512 bytes Espruino starts chucking it away. If you check 'E.getErrorFlags' I bet you'll find a BUFFER_FULL error in there.
    • Finally there was an issue where pipes no longer picked up the close event from sockets properly

    So:

    • git pull
    • Add res.end() into your handler immediately (Espruino won't close the connection until content-length is received)
    • Change chunksize to 1024 (it won't really hurt having it big as the data is already in memory)

    And that's it - it should work. The whole pipe overflowing thing is a pain, but I don't see a nice way around it unless the pipe is allowed to ignore the chunksize argument when it sees that it has a bunch of data available for it - but that could cause problems for endpoints that really only do want small amounts of data.

About

Avatar for Gordon @Gordon started