mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
adjust user agent name
This commit is contained in:
parent
1609ffc92a
commit
f104044a09
1 changed files with 9 additions and 1 deletions
10
anki/sync.py
10
anki/sync.py
|
@ -464,9 +464,13 @@ class AnkiRequestsClient(object):
|
|||
|
||||
def post(self, url, data, headers):
|
||||
data = _MonitoringFile(data)
|
||||
headers['User-Agent'] = self._agentName()
|
||||
return self.session.post(url, data=data, headers=headers, stream=True)
|
||||
|
||||
def get(self, url):
|
||||
def get(self, url, headers=None):
|
||||
if headers is None:
|
||||
headers = {}
|
||||
headers['User-Agent'] = self._agentName()
|
||||
return self.session.get(url, stream=True)
|
||||
|
||||
def streamContent(self, resp):
|
||||
|
@ -478,6 +482,10 @@ class AnkiRequestsClient(object):
|
|||
buf.write(chunk)
|
||||
return buf.getvalue()
|
||||
|
||||
def _agentName(self):
|
||||
from anki import version
|
||||
return "Anki {}".format(version)
|
||||
|
||||
class _MonitoringFile(io.BufferedReader):
|
||||
def read(self, size=-1):
|
||||
data = io.BufferedReader.read(self, HTTP_BUF_SIZE)
|
||||
|
|
Loading…
Reference in a new issue