0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-request-method-delete-payload.js
Austin Wright d4e365f606
test: verify request payload is uploaded consistently
Node.js seems to change how it is uploaded based on the method,
but HTTP doesn't make any distinction.

Co-authored-by: Austin Wright <aaa@bzfx.net>
Co-authored-by: Lenvin Gonsalves <lenvingonsalves@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/34066
Refs: https://github.com/nodejs/node/issues/27880
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-05-12 21:15:30 +02:00

31 lines
862 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const data = 'PUT / HTTP/1.1\r\n\r\n';
const server = http.createServer(common.mustCall(function(req, res) {
req.on('data', function(chunk) {
assert.strictEqual(chunk, Buffer.from(data));
});
res.setHeader('Content-Type', 'text/plain');
for (let i = 0; i < req.rawHeaders.length; i += 2) {
if (req.rawHeaders[i].toLowerCase() === 'host') continue;
if (req.rawHeaders[i].toLowerCase() === 'connection') continue;
res.write(`${req.rawHeaders[i]}: ${req.rawHeaders[i + 1]}\r\n`);
}
res.end();
})).unref();
server.listen(0, common.mustCall(() => {
const port = server.address().port;
const req = http.request({ method: 'DELETE', port }, function(res) {
res.resume();
});
req.write(data);
req.end();
}));