Permalink
Browse files

http: remove deprecated Client interface

PR-URL: #8104
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information...
mscdex committed Aug 14, 2016
1 parent 07dbf73 commit 2cc7fa5e7dabdf10bf26efc4ab8dbffd36dba23e
Showing with 13 additions and 168 deletions.
  1. +0 −11 doc/api/http.md
  2. +10 −76 lib/http.js
  3. +3 −11 test/parallel/test-http-client-race-2.js
  4. +0 −70 test/parallel/test-http-legacy.js
@@ -1336,17 +1336,6 @@ A collection of all the standard HTTP response status codes, and the
short description of each. For example, `http.STATUS_CODES[404] === 'Not
Found'`.
## http.createClient([port][, host])
<!-- YAML
added: v0.1.13
deprecated: v0.3.6
-->
> Stability: 0 - Deprecated: Use [`http.request()`][] instead.
Constructs a new HTTP client. `port` and `host` refer to the server to be
connected to.
## http.createServer([requestListener])
<!-- YAML
added: v0.1.13
@@ -1,28 +1,23 @@
'use strict';
const util = require('util');
const internalUtil = require('internal/util');
const EventEmitter = require('events');
exports.IncomingMessage = require('_http_incoming').IncomingMessage;
const common = require('_http_common');
exports.METHODS = common.methods.slice().sort();
exports.OutgoingMessage = require('_http_outgoing').OutgoingMessage;
exports.METHODS = require('_http_common').methods.slice().sort();
const agent = require('_http_agent');
exports.Agent = agent.Agent;
exports.globalAgent = agent.globalAgent;
const server = require('_http_server');
exports.ServerResponse = server.ServerResponse;
exports.STATUS_CODES = server.STATUS_CODES;
exports._connectionListener = server._connectionListener;
const Server = exports.Server = server.Server;
const agent = require('_http_agent');
const Agent = exports.Agent = agent.Agent;
exports.globalAgent = agent.globalAgent;
exports.createServer = function(requestListener) {
return new Server(requestListener);
};
const client = require('_http_client');
const ClientRequest = exports.ClientRequest = client.ClientRequest;
@@ -36,64 +31,3 @@ exports.get = function(options, cb) {
req.end();
return req;
};
exports._connectionListener = server._connectionListener;
const Server = exports.Server = server.Server;
exports.createServer = function(requestListener) {
return new Server(requestListener);
};
// Legacy Interface
function Client(port, host) {
if (!(this instanceof Client)) return new Client(port, host);
EventEmitter.call(this);
host = host || 'localhost';
port = port || 80;
this.host = host;
this.port = port;
this.agent = new Agent({ host: host, port: port, maxSockets: 1 });
}
util.inherits(Client, EventEmitter);
Client.prototype.request = function(method, path, headers) {
var self = this;
var options = {};
options.host = self.host;
options.port = self.port;
if (method[0] === '/') {
headers = path;
path = method;
method = 'GET';
}
options.method = method;
options.path = path;
options.headers = headers;
options.agent = self.agent;
var c = new ClientRequest(options);
c.on('error', function(e) {
self.emit('error', e);
});
// The old Client interface emitted 'end' on socket end.
// This doesn't map to how we want things to operate in the future
// but it will get removed when we remove this legacy interface.
c.on('socket', function(s) {
s.on('end', function() {
if (self._decoder) {
var ret = self._decoder.end();
if (ret)
self.emit('data', ret);
}
self.emit('end');
});
});
return c;
};
exports.Client = internalUtil.deprecate(Client, 'http.Client is deprecated.');
exports.createClient = internalUtil.deprecate(function(port, host) {
return new Client(port, host);
}, 'http.createClient is deprecated. Use http.request instead.');
@@ -34,13 +34,10 @@ var body2 = '';
var body3 = '';
server.on('listening', function() {
var client = http.createClient(this.address().port);
//
// Client #1 is assigned Parser #1
//
var req1 = client.request('/1');
req1.end();
var req1 = http.get({ port: this.address().port, path: '/1' });
req1.on('response', function(res1) {
res1.setEncoding('utf8');
@@ -58,15 +55,11 @@ server.on('listening', function() {
// The bug would introduce itself here: Client #2 would be allocated the
// parser that previously belonged to Client #1. But we're not finished
// with Client #1 yet!
//
var client2 = http.createClient(server.address().port);
//
// At this point, the bug would manifest itself and crash because the
// internal state of the parser was no longer valid for use by Client #1
//
var req2 = client.request('/2');
req2.end();
var req2 = http.get({ port: server.address().port, path: '/2' });
req2.on('response', function(res2) {
res2.setEncoding('utf8');
res2.on('data', function(chunk) { body2 += chunk; });
@@ -76,8 +69,7 @@ server.on('listening', function() {
// Just to be really sure we've covered all our bases, execute a
// request using client2.
//
var req3 = client2.request('/3');
req3.end();
var req3 = http.get({ port: server.address().port, path: '/3' });
req3.on('response', function(res3) {
res3.setEncoding('utf8');
res3.on('data', function(chunk) { body3 += chunk; });

This file was deleted.

Oops, something went wrong.

0 comments on commit 2cc7fa5

Please sign in to comment.