Skip to content
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

Fix #236 DELETE should set Content-Length to 0 #711

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ Request.prototype.request = function(){
// request
var req = this.req = mod.request(options);
if ('HEAD' != options.method) req.setHeader('Accept-Encoding', 'gzip, deflate');
if ('DELETE' == options.method) req.setHeader('Content-Length', 0);
this.protocol = url.protocol;
this.host = url.host;

Expand Down
8 changes: 8 additions & 0 deletions test/node/content-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ describe('req.set("Content-Type", contentType)', function(){
});
});

it('should delete with a content-length of 0', function(done){
request.del('http://localhost:3005/nonexistant')
.end(function(err, res) {
assert(err)
res.request.req._headers['content-length'].should.equal(0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a better way to check the header that has been sent?

return done();
})
})
});