New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to be able to get POSTed file data in HTTP Server #226
Comments
Unfortunately this only works with very small POSTs. Generally one needs to buffer all the data received from Currently, I seem to be getting exactly 96 chars when the Refs: |
There is a The 96 chars may just be to do with the amount needed to parse the header... At the moment everything is being transferred to/from the CC3000 in 32 byte packets. |
Ah, makes sense :) Unfortunately the I actually found all the events quite confusing, so I spent some time in the spec and made this: router.addRoute('/post', function(req, res) {
req.on('data', function(data) {
console.log('request data: ' + data);
});
req.on('close', function() {
// Indicates that the underlaying connection was closed.
// Just like 'end', this event occurs only once per response.
// BUT... we might need to process data before connection closes!
console.log('request close (http.incomingMessage)');
});
req.on('end', function() {
// This event fires when no more data will be provided (but connection
// is still open), and all data was consumed [by data event handlers].
console.log('request stream end (http.incomingMessage stream)');
});
res.on('close', function() {
// Indicates that the underlying connection was terminated before
// response.end() was called or able to flush.
console.log('response close (http.ServerResponse)');
});
res.on('finish', function() {
// Emitted when the response has been sent.
console.log('response finish (http.serverResponse)');
});
// should also test when client disconnects before this!
setTimeout(function() {
console.log('res.end()');
res.end();
}, 5000);
}); Output (if server ends request):
We shouldn't actually get the My current workaround relies on knowing the expected lastChar of the body, and it works great, until I get unlucky and user supplied data happens to include this char and be chunked at that point :> So, not urgent for me, and doesn't seem to affect anyone else (yet), but definitely needs to get fixed at some point. |
Sure - thanks for the code above - it helps a lot :) Just a quick one though - how do we know that the client has finished sending? is it as simple as checking against the content-length header? (that might actually be the best workaround for you now?) By the way, if you do get time and fancy poking around, you can actually run Espruino on Linux so could develop/debug changes for this without having to get a toolchain for ARM sorted out :) |
Ooh yeah, in my case that's a much better workaround, thanks! I checked and the requests are indeed sent with the Anyway, I had to dig around for the "real" answer, and I hope I got it right since I'm a bit out of my league here, but the http server is a socket server with allowHalfOpen set to true (source). And although I couldn't find a ref, it seems to be standard practice for the client to send a TCP FIN after the POST request (or any request I guess). So I think the correct time to fire the Re running on Linux, I saw that this morning! Quite keen to check it out when I get a chance (how would I test HTTP though?). I haven't touched C in some 15 years or so, but I used to be quite proficient :> But yeah, would love to rather send PRs than problems hehe. If I'm unsure, I'll just send a link to the commit on a different branch of my fork. Thanks! |
Well, in Espruino there's no socket implementation right now, so the HTTP server is standalone. You can test HTTP in Linux just like with the Espruino Board (the HTTP server is part of Espruino rather than the CC3000) - just set the port above 1024 or you'll have to run it as a superuser :) |
Hi, just to clarify: when clients send transfer-encoding: chunked they never send content-length; The whole purpose is being able to send a possibly unknown amount of data. So you absolutely have to buffer the data, ideally to SD if available. |
You can now do this just fine:
However in the example above, the SD card is too slow to cope with ESP8266 and high baud rates. You can still use lower baud rates, other network devices, or do something other than write to SD though. |
http://forum.espruino.com/conversations/594/
The text was updated successfully, but these errors were encountered: