2015-08-11 20:02:22 -07:00
|
|
|
'use strict';
|
2016-05-29 03:06:56 -04:00
|
|
|
require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
|
|
const net = require('net');
|
2015-08-11 20:02:22 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let received = '';
|
2015-08-11 20:02:22 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(function(req, res) {
|
2015-08-11 20:02:22 -07:00
|
|
|
res.writeHead(200);
|
|
|
|
res.end();
|
|
|
|
|
|
|
|
req.socket.on('data', function(data) {
|
|
|
|
received += data;
|
|
|
|
});
|
|
|
|
|
2019-04-20 22:42:27 +08:00
|
|
|
assert.strictEqual(req.socket.on, req.socket.addListener);
|
|
|
|
assert.strictEqual(req.socket.prependListener,
|
|
|
|
net.Socket.prototype.prependListener);
|
|
|
|
|
2015-08-11 20:02:22 -07:00
|
|
|
server.close();
|
2016-05-29 03:06:56 -04:00
|
|
|
}).listen(0, function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const socket = net.connect(this.address().port, function() {
|
2015-08-11 20:02:22 -07:00
|
|
|
socket.write('PUT / HTTP/1.1\r\n\r\n');
|
|
|
|
|
|
|
|
socket.once('data', function() {
|
|
|
|
socket.end('hello world');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(received, 'hello world');
|
2015-08-11 20:02:22 -07:00
|
|
|
});
|