2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
|
|
|
const http = require('http');
|
2011-10-18 14:15:58 +01:00
|
|
|
|
2013-11-04 09:39:29 -08:00
|
|
|
// Test that the DELETE, PATCH and PURGE verbs get passed through correctly
|
2011-10-18 14:15:58 +01:00
|
|
|
|
2013-11-04 09:39:29 -08:00
|
|
|
['DELETE', 'PATCH', 'PURGE'].forEach(function(method, index) {
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(common.mustCall(function(req, res) {
|
2016-07-15 15:43:24 -04:00
|
|
|
assert.strictEqual(req.method, method);
|
2012-02-17 23:45:50 +01:00
|
|
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
|
|
|
res.write('hello ');
|
|
|
|
res.write('world\n');
|
|
|
|
res.end();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0);
|
2011-10-18 14:15:58 +01:00
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
server.on('listening', common.mustCall(function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const c = net.createConnection(this.address().port);
|
|
|
|
let server_response = '';
|
2011-10-18 14:15:58 +01:00
|
|
|
|
2012-02-17 23:45:50 +01:00
|
|
|
c.setEncoding('utf8');
|
2011-10-18 14:15:58 +01:00
|
|
|
|
2012-02-17 23:45:50 +01:00
|
|
|
c.on('connect', function() {
|
|
|
|
c.write(method + ' / HTTP/1.0\r\n\r\n');
|
|
|
|
});
|
2011-10-18 14:15:58 +01:00
|
|
|
|
2012-02-17 23:45:50 +01:00
|
|
|
c.on('data', function(chunk) {
|
|
|
|
console.log(chunk);
|
|
|
|
server_response += chunk;
|
|
|
|
});
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
c.on('end', common.mustCall(function() {
|
|
|
|
const m = server_response.split('\r\n\r\n');
|
|
|
|
assert.strictEqual(m[1], 'hello world\n');
|
2012-02-17 23:45:50 +01:00
|
|
|
c.end();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2011-10-18 14:15:58 +01:00
|
|
|
|
2012-02-17 23:45:50 +01:00
|
|
|
c.on('close', function() {
|
|
|
|
server.close();
|
|
|
|
});
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2011-10-18 14:15:58 +01:00
|
|
|
});
|