Skip to content

Commit

Permalink
http: remove deprecated Client interface
Browse files Browse the repository at this point in the history
PR-URL: #8104
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
mscdex committed Aug 30, 2016
1 parent 07dbf73 commit 2cc7fa5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 168 deletions.
11 changes: 0 additions & 11 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
86 changes: 10 additions & 76 deletions lib/http.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.');
14 changes: 3 additions & 11 deletions test/parallel/test-http-client-race-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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; });
Expand All @@ -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; });
Expand Down
70 changes: 0 additions & 70 deletions test/parallel/test-http-legacy.js

This file was deleted.

0 comments on commit 2cc7fa5

Please sign in to comment.