diff --git a/modules/fediverse/ap_utils.py b/modules/fediverse/ap_utils.py index bd0cacf4..a2191014 100644 --- a/modules/fediverse/ap_utils.py +++ b/modules/fediverse/ap_utils.py @@ -7,7 +7,6 @@ LD_TYPE = ("application/ld+json; " "profile=\"https://www.w3.org/ns/activitystreams\"") JRD_TYPE = "application/jrd+json" ACTIVITY_TYPE = "application/activity+json" -USERAGENT = "BitBot (%s) Fediverse" % IRCBot.VERSION def split_username(s): if s[0] == "@": @@ -26,7 +25,7 @@ def activity_request(url, data=None, method="GET", type=ACTIVITY_TYPE, else: headers = {"Accept": type} - request = utils.http.Request(url, headers=headers, useragent=USERAGENT, + request = utils.http.Request(url, headers=headers, content_type=content_type, post_data=data, method=method, json=True, json_body=True, fallback_encoding="utf8") return utils.http.request(request) 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