Skip to content

Commit 2cc7fa5

Browse files
committed
http: remove deprecated Client interface
PR-URL: #8104 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 07dbf73 commit 2cc7fa5

File tree

4 files changed

+13
-168
lines changed

4 files changed

+13
-168
lines changed

doc/api/http.md

-11
Original file line numberDiff line numberDiff line change
@@ -1336,17 +1336,6 @@ A collection of all the standard HTTP response status codes, and the
13361336
short description of each. For example, `http.STATUS_CODES[404] === 'Not
13371337
Found'`.
13381338

1339-
## http.createClient([port][, host])
1340-
<!-- YAML
1341-
added: v0.1.13
1342-
deprecated: v0.3.6
1343-
-->
1344-
1345-
> Stability: 0 - Deprecated: Use [`http.request()`][] instead.
1346-
1347-
Constructs a new HTTP client. `port` and `host` refer to the server to be
1348-
connected to.
1349-
13501339
## http.createServer([requestListener])
13511340
<!-- YAML
13521341
added: v0.1.13

lib/http.js

+10-76
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
'use strict';
2-
3-
const util = require('util');
4-
const internalUtil = require('internal/util');
5-
const EventEmitter = require('events');
6-
7-
82
exports.IncomingMessage = require('_http_incoming').IncomingMessage;
93

10-
11-
const common = require('_http_common');
12-
exports.METHODS = common.methods.slice().sort();
13-
14-
154
exports.OutgoingMessage = require('_http_outgoing').OutgoingMessage;
165

6+
exports.METHODS = require('_http_common').methods.slice().sort();
7+
8+
const agent = require('_http_agent');
9+
exports.Agent = agent.Agent;
10+
exports.globalAgent = agent.globalAgent;
1711

1812
const server = require('_http_server');
1913
exports.ServerResponse = server.ServerResponse;
2014
exports.STATUS_CODES = server.STATUS_CODES;
15+
exports._connectionListener = server._connectionListener;
16+
const Server = exports.Server = server.Server;
2117

22-
23-
const agent = require('_http_agent');
24-
const Agent = exports.Agent = agent.Agent;
25-
exports.globalAgent = agent.globalAgent;
18+
exports.createServer = function(requestListener) {
19+
return new Server(requestListener);
20+
};
2621

2722
const client = require('_http_client');
2823
const ClientRequest = exports.ClientRequest = client.ClientRequest;
@@ -36,64 +31,3 @@ exports.get = function(options, cb) {
3631
req.end();
3732
return req;
3833
};
39-
40-
exports._connectionListener = server._connectionListener;
41-
const Server = exports.Server = server.Server;
42-
43-
exports.createServer = function(requestListener) {
44-
return new Server(requestListener);
45-
};
46-
47-
48-
// Legacy Interface
49-
50-
function Client(port, host) {
51-
if (!(this instanceof Client)) return new Client(port, host);
52-
EventEmitter.call(this);
53-
54-
host = host || 'localhost';
55-
port = port || 80;
56-
this.host = host;
57-
this.port = port;
58-
this.agent = new Agent({ host: host, port: port, maxSockets: 1 });
59-
}
60-
util.inherits(Client, EventEmitter);
61-
Client.prototype.request = function(method, path, headers) {
62-
var self = this;
63-
var options = {};
64-
options.host = self.host;
65-
options.port = self.port;
66-
if (method[0] === '/') {
67-
headers = path;
68-
path = method;
69-
method = 'GET';
70-
}
71-
options.method = method;
72-
options.path = path;
73-
options.headers = headers;
74-
options.agent = self.agent;
75-
var c = new ClientRequest(options);
76-
c.on('error', function(e) {
77-
self.emit('error', e);
78-
});
79-
// The old Client interface emitted 'end' on socket end.
80-
// This doesn't map to how we want things to operate in the future
81-
// but it will get removed when we remove this legacy interface.
82-
c.on('socket', function(s) {
83-
s.on('end', function() {
84-
if (self._decoder) {
85-
var ret = self._decoder.end();
86-
if (ret)
87-
self.emit('data', ret);
88-
}
89-
self.emit('end');
90-
});
91-
});
92-
return c;
93-
};
94-
95-
exports.Client = internalUtil.deprecate(Client, 'http.Client is deprecated.');
96-
97-
exports.createClient = internalUtil.deprecate(function(port, host) {
98-
return new Client(port, host);
99-
}, 'http.createClient is deprecated. Use http.request instead.');

test/parallel/test-http-client-race-2.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ var body2 = '';
3434
var body3 = '';
3535

3636
server.on('listening', function() {
37-
var client = http.createClient(this.address().port);
38-
3937
//
4038
// Client #1 is assigned Parser #1
4139
//
42-
var req1 = client.request('/1');
43-
req1.end();
40+
var req1 = http.get({ port: this.address().port, path: '/1' });
4441
req1.on('response', function(res1) {
4542
res1.setEncoding('utf8');
4643

@@ -58,15 +55,11 @@ server.on('listening', function() {
5855
// The bug would introduce itself here: Client #2 would be allocated the
5956
// parser that previously belonged to Client #1. But we're not finished
6057
// with Client #1 yet!
61-
//
62-
var client2 = http.createClient(server.address().port);
63-
6458
//
6559
// At this point, the bug would manifest itself and crash because the
6660
// internal state of the parser was no longer valid for use by Client #1
6761
//
68-
var req2 = client.request('/2');
69-
req2.end();
62+
var req2 = http.get({ port: server.address().port, path: '/2' });
7063
req2.on('response', function(res2) {
7164
res2.setEncoding('utf8');
7265
res2.on('data', function(chunk) { body2 += chunk; });
@@ -76,8 +69,7 @@ server.on('listening', function() {
7669
// Just to be really sure we've covered all our bases, execute a
7770
// request using client2.
7871
//
79-
var req3 = client2.request('/3');
80-
req3.end();
72+
var req3 = http.get({ port: server.address().port, path: '/3' });
8173
req3.on('response', function(res3) {
8274
res3.setEncoding('utf8');
8375
res3.on('data', function(chunk) { body3 += chunk; });

test/parallel/test-http-legacy.js

-70
This file was deleted.

0 commit comments

Comments
 (0)