[node] net.Server, http.Server, http.ServerRequest, http.ServerResponse, http.ClientRequest, http.IncomingMessage, http.ClientResponse fix from interface to class and add constructors. (#18281)

* [node] net.Server, http.Server, http.ServerRequest, http.ServerResponse, http.ClientRequest, http.IncomingMessage, http.ClientResponse, http.Server fix from interface to class and add constructors.

* add http constructor tests

* fix lint

* add author

* fix: remove rejectUnauthorized,
createConnection callback make more detailed,
http.Server requestListener more detailed,
add export OutgoingMessage, ServerResponse and ClientRequest extends OutgoingMessage.
combine the constructors in ClientRequest

* add more http tests

* remove trailing space

* remove deprecated apis, private props not documented, seperate httpHeaders to incoming and outgoing, fix rejectUnauthorized prop misplaced, use () => void for callback

* typo

* settimeout return this
This commit is contained in:
william chang(張仲威)
2017-07-25 01:37:46 +08:00
committed by Andy
parent 910023509a
commit dfda34b1c2
2 changed files with 167 additions and 65 deletions

View File

@@ -1062,6 +1062,89 @@ namespace tls_tests {
////////////////////////////////////////////////////
namespace http_tests {
// http Server
{
var server: http.Server = new http.Server();
}
// http IncomingMessage
// http ServerResponse
{
// incoming
var incoming: http.IncomingMessage = new http.IncomingMessage(new net.Socket());
incoming.setEncoding('utf8');
// stream
incoming.pause();
incoming.resume();
// response
var res: http.ServerResponse = new http.ServerResponse(incoming);
// test headers
res.setHeader('Content-Type', 'text/plain');
var bool: boolean = res.hasHeader('Content-Type');
var headers: string[] = res.getHeaderNames();
// trailers
res.addTrailers([
['x-fOo', 'xOxOxOx'],
['x-foO', 'OxOxOxO'],
['X-fOo', 'xOxOxOx'],
['X-foO', 'OxOxOxO']
]);
res.addTrailers({'x-foo': 'bar'});
// writeHead
res.writeHead(200, 'OK\r\nContent-Type: text/html\r\n');
res.writeHead(200, { 'Transfer-Encoding': 'chunked' });
res.writeHead(200);
// write string
res.write('Part of my res.');
// write buffer
const chunk = Buffer.alloc(16390, 'Й');
req.write(chunk);
res.write(chunk, 'hex');
// end
res.end("end msg");
// without msg
res.end();
// flush
res.flushHeaders();
}
// http ClientRequest
{
var req: http.ClientRequest = new http.ClientRequest("https://www.google.com");
var req: http.ClientRequest = new http.ClientRequest(new url.URL("https://www.google.com"));
var req: http.ClientRequest = new http.ClientRequest({ path: 'http://0.0.0.0' });
// header
req.setHeader('Content-Type', 'text/plain');
var bool: boolean = req.hasHeader('Content-Type');
var headers: string[] = req.getHeaderNames();
req.removeHeader('Date');
// write
const chunk = Buffer.alloc(16390, 'Й');
req.write(chunk);
req.write('a');
req.end();
// abort
req.abort();
// connection
req.connection.on('pause', () => {});
// event
req.on('data', () => {});
}
{
// Status codes
var codeMessage = http.STATUS_CODES['400'];