Content-length issue with form-data and streams #446

Closed
jmzrlz opened this Issue Feb 26, 2013 · 4 comments

Projects

None yet

4 participants

@jmzrlz
jmzrlz commented Feb 26, 2013

Saw a bug similar to this which is now closed, for some reason, but if you think this is a dupe go ahead and close it.

Anyhow, the following:

var upload = request({
    url: 'http://example.com/',
    method: 'POST',
}, function(err, resp, body) {
    console.log(body);
});
var form = upload.form();
form.append('test', 'somestring');
form.append('test2', 'anotherstring');
form.append('Filedata', fs.createReadStream('1M.data'));
form.getLength(function(err, len) {
    upload.setHeader('Content-Length', len);
});

This results in a 411 response from a standard nginx server. Using getLengthSync makes no difference, removing the last 3 lines makes no difference. Also resp.request.headers does contain a content-length with a value which seems correct.

So why is it that it still fails? Why do I have to do any of this in the first place? Your examples should work as is, and this is almost a direct copy of your example in the readme (except the last 3 lines and changing request.post() to request()).

@mikeal
Member
mikeal commented Feb 26, 2013

There is an open bug in the form-data library, which is what underlies request.form, about getting a proper content length.

It's very silly that some servers still require a content length for multipart-form posts but that's reality i guess.

@mikeal mikeal closed this Feb 26, 2013
@leeola
leeola commented Apr 19, 2013

It's very silly that some servers still require a content length for multipart-form posts but that's reality i guess.

@mikeal On a side note, any idea what it is that these servers are doing wrong? I am running into this, and would like to inform the host on what is wrong, but i have no idea hah.

@mikeal
Member
mikeal commented Apr 19, 2013

they don't support transfer-encoding:chunked in multipart.

@T1B0
T1B0 commented Apr 19, 2013

Seems that apache2's mod_php doesn't support transfer-encoding:chunked in multipart either (https://bugs.php.net/bug.php?id=50210) which totally ruins my day.
Is there a way to disable chunked transfer encoding while uploading a stream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment