diff options
| author | 2019-11-20 14:42:34 +0000 | |
|---|---|---|
| committer | 2019-11-20 14:42:34 +0000 | |
| commit | 4d30263315d7b585e4c51b664e1ace2f13195456 (patch) | |
| tree | 4cbeb5ca2555104ce42cccfbcda536784f52896e /src | |
| parent | move things like IRCBot.VERSION to before imports (for utils.http) (diff) | |
| signature | ||
give bitbot a unique User-Agent
closes #206
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/http.py | 11 |
1 files changed, 5 insertions, 6 deletions
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 |
