Skip to content

Commit 584ae7b

Browse files
mikealbnoordhuis
authored andcommitted
Remove http.cat. fixes nodejs#1447
1 parent 721f265 commit 584ae7b

4 files changed

Lines changed: 23 additions & 161 deletions

File tree

lib/http2.js

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,85 +1491,3 @@ exports.Client = Client;
14911491
exports.createClient = function(port, host) {
14921492
return new Client(port, host);
14931493
};
1494-
1495-
exports.cat = function(url, encoding_, headers_) {
1496-
var encoding = 'utf8';
1497-
var headers = {};
1498-
var callback = null;
1499-
1500-
console.error("http.cat will be removed in the near future. use http.get");
1501-
1502-
// parse the arguments for the various options... very ugly
1503-
if (typeof(arguments[1]) == 'string') {
1504-
encoding = arguments[1];
1505-
if (typeof(arguments[2]) == 'object') {
1506-
headers = arguments[2];
1507-
if (typeof(arguments[3]) == 'function') callback = arguments[3];
1508-
} else {
1509-
if (typeof(arguments[2]) == 'function') callback = arguments[2];
1510-
}
1511-
} else {
1512-
// didn't specify encoding
1513-
if (typeof(arguments[1]) == 'object') {
1514-
headers = arguments[1];
1515-
callback = arguments[2];
1516-
} else {
1517-
callback = arguments[1];
1518-
}
1519-
}
1520-
1521-
var url = require('url').parse(url);
1522-
1523-
var hasHost = false;
1524-
if (Array.isArray(headers)) {
1525-
for (var i = 0, l = headers.length; i < l; i++) {
1526-
if (headers[i][0].toLowerCase() === 'host') {
1527-
hasHost = true;
1528-
break;
1529-
}
1530-
}
1531-
} else if (typeof headers === 'Object') {
1532-
var keys = Object.keys(headers);
1533-
for (var i = 0, l = keys.length; i < l; i++) {
1534-
var key = keys[i];
1535-
if (key.toLowerCase() == 'host') {
1536-
hasHost = true;
1537-
break;
1538-
}
1539-
}
1540-
}
1541-
if (!hasHost) headers['Host'] = url.hostname;
1542-
1543-
var content = '';
1544-
1545-
var path = (url.pathname || '/') + (url.search || '') + (url.hash || '');
1546-
var callbackSent = false;
1547-
var req = exports.request({port: url.port || 80, host: url.hostname, path: path}, function(res) {
1548-
if (res.statusCode < 200 || res.statusCode >= 300) {
1549-
if (callback && !callbackSent) {
1550-
callback(res.statusCode);
1551-
callbackSent = true;
1552-
}
1553-
client.end();
1554-
return;
1555-
}
1556-
res.setEncoding(encoding);
1557-
res.addListener('data', function(chunk) { content += chunk; });
1558-
res.addListener('end', function() {
1559-
if (callback && !callbackSent) {
1560-
callback(null, content);
1561-
callbackSent = true;
1562-
}
1563-
});
1564-
});
1565-
1566-
1567-
req.addListener('error', function(err) {
1568-
if (callback && !callbackSent) {
1569-
callback(err);
1570-
callbackSent = true;
1571-
}
1572-
});
1573-
1574-
req.end();
1575-
};

test/simple/test-http-cat.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

test/simple/test-http-chunked.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,23 @@ var server = http.createServer(function(req, res) {
3737
res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'});
3838
res.end(UTF8_STRING, 'utf8');
3939
});
40-
server.listen(common.PORT);
40+
server.listen(common.PORT, function() {
41+
var data = '';
42+
var get = http.get({path:'/', host:'localhost', port:common.PORT}, function (x) {
43+
x.setEncoding('utf8')
44+
x.on('data', function (c) {data += c});
45+
x.on('error', function (e) {
46+
throw e;
47+
})
48+
x.on('end', function () {
49+
assert.equal('string', typeof data);
50+
console.log('here is the response:');
51+
assert.equal(UTF8_STRING, data);
52+
console.log(data);
53+
server.close();
54+
})
55+
})
56+
get.on('error', function (e) {throw e});
57+
get.end();
4158

42-
server.addListener('listening', function() {
43-
http.cat('http://127.0.0.1:' + common.PORT + '/', 'utf8',
44-
function(err, data) {
45-
if (err) throw err;
46-
assert.equal('string', typeof data);
47-
console.log('here is the response:');
48-
assert.equal(UTF8_STRING, data);
49-
console.log(data);
50-
server.close();
51-
});
5259
});

test/simple/test-http-set-timeout.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ server.listen(common.PORT, function() {
4141
throw new Error('Timeout was not sucessful');
4242
}, 2000);
4343

44-
var url = 'http://localhost:' + common.PORT + '/';
45-
46-
http.cat(url, 'utf8', function(err, content) {
44+
var x = http.get({port:common.PORT, path:'/'});
45+
x.on('error', function () {
4746
clearTimeout(errorTimer);
4847
console.log('HTTP REQUEST COMPLETE (this is good)');
49-
});
48+
})
49+
x.end();
50+
5051
});

0 commit comments

Comments
 (0)