Skip to content

Commit

Permalink
Merge pull request #203 from egirshov/fix-66
Browse files Browse the repository at this point in the history
additional fix for empty requests
  • Loading branch information
svnlto committed Mar 14, 2013
2 parents 55caee5 + 0b675be commit 1605db0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/incoming_form.js
Expand Up @@ -276,9 +276,14 @@ IncomingForm.prototype._error = function(err) {
};

IncomingForm.prototype._parseContentLength = function() {
this.bytesReceived = 0;
if (this.headers['content-length']) {
this.bytesReceived = 0;
this.bytesExpected = parseInt(this.headers['content-length'], 10);
} else if (this.headers['transfer-encoding'] === undefined) {
this.bytesExpected = 0;
}

if (this.bytesExpected !== null) {
this.emit('progress', this.bytesReceived, this.bytesExpected);
}
};
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/http/misc/minimal.http
@@ -0,0 +1,3 @@
POST /upload HTTP/1.1
Host: localhost:8080

1 change: 1 addition & 0 deletions test/fixture/js/misc.js
Expand Up @@ -2,4 +2,5 @@ module.exports = {
'empty.http': [],
'empty-urlencoded.http': [],
'empty-multipart.http': [],
'minimal.http': [],
};
7 changes: 5 additions & 2 deletions test/legacy/simple/test-incoming-form.js
Expand Up @@ -378,9 +378,12 @@ test(function parseContentLength() {
var HEADERS = {};

form.headers = {};
gently.expect(form, 'emit', function(event, bytesReceived, bytesExpected) {
assert.equal(event, 'progress');
assert.equal(bytesReceived, 0);
assert.equal(bytesExpected, 0);
});
form._parseContentLength();
assert.strictEqual(form.bytesReceived, null);
assert.strictEqual(form.bytesExpected, null);

form.headers['content-length'] = '8';
gently.expect(form, 'emit', function(event, bytesReceived, bytesExpected) {
Expand Down

0 comments on commit 1605db0

Please sign in to comment.