mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
28 lines
669 B
JavaScript
28 lines
669 B
JavaScript
|
'use strict';
|
||
|
|
||
|
const common = require('../common');
|
||
|
const { strictEqual } = require('assert');
|
||
|
const { createServer, request } = require('http');
|
||
|
|
||
|
const server = createServer(common.mustCall((req, res) => {
|
||
|
strictEqual(req.method, 'QUERY');
|
||
|
res.end('OK');
|
||
|
}));
|
||
|
|
||
|
server.listen(0, common.mustCall(() => {
|
||
|
const req = request({ port: server.address().port, method: 'QUERY' }, common.mustCall((res) => {
|
||
|
strictEqual(res.statusCode, 200);
|
||
|
|
||
|
let buffer = '';
|
||
|
res.setEncoding('utf-8');
|
||
|
|
||
|
res.on('data', (c) => buffer += c);
|
||
|
res.on('end', common.mustCall(() => {
|
||
|
strictEqual(buffer, 'OK');
|
||
|
server.close();
|
||
|
}));
|
||
|
}));
|
||
|
|
||
|
req.end();
|
||
|
}));
|