mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
http: remove deprecated Client interface
PR-URL: https://github.com/nodejs/node/pull/8104 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
07dbf7313d
commit
2cc7fa5e7d
4 changed files with 13 additions and 168 deletions
86
lib/http.js
86
lib/http.js
|
@ -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.');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue