X-Git-Url: https://plomlompom.com/repos/?p=plomlombot-irc.git;a=blobdiff_plain;f=plomlombot.py;h=ede4dca9b1dccc6b55861062daea277df26ba415;hp=7224b29e2ccff2a90504a113676edd625278253e;hb=bc851d6d6fc8f0dd1c61b2fc57c08937c46fb529;hpb=2fc56d6691472c34fc5487c97b11075f0824cf36 diff --git a/plomlombot.py b/plomlombot.py index 7224b29..ede4dca 100755 --- a/plomlombot.py +++ b/plomlombot.py @@ -339,17 +339,23 @@ def handle_url(url, notice, show_url=False): return True try: - r = requests.get(url, timeout=15) + r = requests.get(url, timeout=15, stream=True) + r.raw.decode_content = True + text = r.raw.read(10000000+1) + if len(text) > 10000000: + raise ValueError('Too large a response') except (requests.exceptions.TooManyRedirects, requests.exceptions.ConnectionError, requests.exceptions.InvalidURL, + requests.exceptions.ReadTimeout, UnicodeError, + ValueError, requests.exceptions.InvalidSchema) as error: notice("TROUBLE FOLLOWING URL: " + str(error)) return if mobile_twitter_hack(url): return - title = bs4.BeautifulSoup(r.text, "html5lib").title + title = bs4.BeautifulSoup(text, "html5lib").title if title and title.string: prefix = "PAGE TITLE: " if show_url: