From 4d30263315d7b585e4c51b664e1ace2f13195456 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 20 Nov 2019 14:42:34 +0000 Subject: give bitbot a unique User-Agent closes #206 --- src/utils/http.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/utils') diff --git a/src/utils/http.py b/src/utils/http.py index f31da62c..3cae97ea 100644 --- a/src/utils/http.py +++ b/src/utils/http.py @@ -1,9 +1,8 @@ import asyncio, codecs, ipaddress, re, signal, socket, traceback, typing import urllib.error, urllib.parse, uuid import json as _json -import bs4, netifaces, requests -import tornado.httpclient -from src import utils +import bs4, netifaces, requests, tornado.httpclient +from src import IRCBot, utils REGEX_URL = re.compile("https?://\S+", re.I) @@ -29,8 +28,8 @@ def url_sanitise(url: str): url = url[:-1] return url -DEFAULT_USERAGENT = ("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 " - "(KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36") +USERAGENT = "Mozilla/5.0 (compatible; BitBot/%s; +%s" % ( + IRCBot.VERSION, IRCBot.URL) RESPONSE_MAX = (1024*1024)*100 SOUP_CONTENT_TYPES = ["text/html", "text/xml", "application/xml"] @@ -113,7 +112,7 @@ class Request(object): if not "Accept-Language" in headers: headers["Accept-Language"] = "en-GB" if not "User-Agent" in headers: - headers["User-Agent"] = self.useragent or DEFAULT_USERAGENT + headers["User-Agent"] = self.useragent or USERAGENT if not "Content-Type" in headers and self.content_type: headers["Content-Type"] = self.content_type return headers -- cgit v1.3.1-10-gc9f91