mirror of
https://github.com/reality/dbot.git
synced 2024-12-25 04:02:39 +01:00
fix crash on too big of a request [Close #332]
This commit is contained in:
parent
c376ab97ac
commit
6176dd5695
@ -11,7 +11,9 @@ var link = function(dbot) {
|
|||||||
this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||||
this.links = {};
|
this.links = {};
|
||||||
this.fetchTitle = function(event, link) {
|
this.fetchTitle = function(event, link) {
|
||||||
request(link, function(error, response, body) {
|
var limit = 25 * 1000,
|
||||||
|
size = 0,
|
||||||
|
page = request(link, function(error, response, body) {
|
||||||
if(!error && response.statusCode == 200) {
|
if(!error && response.statusCode == 200) {
|
||||||
body = body.replace(/(\r\n|\n\r|\n)/gm, " ");
|
body = body.replace(/(\r\n|\n\r|\n)/gm, " ");
|
||||||
var title = body.valMatch(/<title>(.*)<\/title>/, 2);
|
var title = body.valMatch(/<title>(.*)<\/title>/, 2);
|
||||||
@ -20,6 +22,14 @@ var link = function(dbot) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
page.on('data', function(chunk) {
|
||||||
|
size += chunk.length;
|
||||||
|
if(size > limit) {
|
||||||
|
page.abort();
|
||||||
|
event.reply('request too big, fuck off');
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var commands = {
|
var commands = {
|
||||||
|
Loading…
Reference in New Issue
Block a user