-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
http body dropped when using delete method #19179
Copy link
Copy link
Closed
Labels
questionIssues that look for answers.Issues that look for answers.
Description
From what I can find, due to this line of code if you make an http request with a delete method the body will not be written (although no error will fire):
Line 141 in 4e15679
| this.useChunkedEncodingByDefault = false; |
From what I can find the spec does not forbid and http body being placed (nor discourages) it (however it may not necessarily be a very commonly used). Here's a test case showing/recreating the issue:
FAILS:
const http = require('http');
const url = require('url');
let req_method = 'delete'; // succeeds if you change this to post
let server = http.createServer((req, res) => {
let method = req.method.toLowerCase();
let uri = url.parse(req.url.toLowerCase());
let data = Buffer.alloc(0);
req.on('data', (datum) => data = Buffer.concat([data, datum]));
req.on('end', () => {
console.log(method, uri.path);
console.log(data.toString('utf8'));
console.assert(method === req_method);
console.assert(data.toString('utf8') === 'Delete method should allow a body.');
res.writeHead(200, 'Ok.');
process.exit(1)
})
}).listen(process.env.PORT || 5000, () => {
let req = http.request({"method":req_method, "path":"/test/path", "host":"localhost", "port":5000});
req.write('Delete method should allow a body.');
req.end();
});
A work around is to add req.useChunkedEncodingByDefault = true before write or end. e.g.,
WORKAROUND:
const http = require('http');
const url = require('url');
let req_method = 'delete';
let server = http.createServer((req, res) => {
let method = req.method.toLowerCase();
let uri = url.parse(req.url.toLowerCase());
let data = Buffer.alloc(0);
req.on('data', (datum) => data = Buffer.concat([data, datum]));
req.on('end', () => {
console.log(method, uri.path);
console.log(data.toString('utf8'));
console.assert(method === req_method);
console.assert(data.toString('utf8') === 'Delete method should allow a body.');
res.writeHead(200, 'Ok.');
process.exit(1)
})
}).listen(process.env.PORT || 5000, () => {
let req = http.request({"method":req_method, "path":"/test/path", "host":"localhost", "port":5000});
req.useChunkedEncodingByDefault = true;
req.write('Delete method should allow a body.');
req.end();
});
Happy to submit a PR to see how i can help fix it, just wanted to make sure first there wasn't a disagreement as to whether delete should even have an option of having a body.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionIssues that look for answers.Issues that look for answers.