Skip to content

Commit 915c01b

Browse files
committed
Include a 'User-Agent' header
This is good practice to get an idea about who actually cares for git-pw. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent f20947d commit 915c01b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

git_pw/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pkg_resources
2+
3+
__version__ = pkg_resources.get_distribution('git-pw').version

git_pw/api.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import requests
99

10+
import git_pw
1011
from git_pw import config
1112

1213
if 0: # noqa
@@ -43,6 +44,12 @@ def _get_auth(): # type: () -> requests.auth.AuthBase
4344
sys.exit(1)
4445

4546

47+
def _get_headers(): # type: () -> Dict[str, str]
48+
return {
49+
'User-Agent': 'git-pw ({})'.format(git_pw.__version__),
50+
}
51+
52+
4653
def _get_server(): # type: () -> str
4754
if CONF.server:
4855
return CONF.server.rstrip('/')
@@ -58,7 +65,8 @@ def get(url, params=None): # type: (str, dict) -> requests.Response
5865
LOG.debug('GET %s', url)
5966

6067
try:
61-
rsp = requests.get(url, auth=_get_auth(), params=params)
68+
rsp = requests.get(url, auth=_get_auth(), headers=_get_headers(),
69+
params=params)
6270
rsp.raise_for_status()
6371
except requests.exceptions.RequestException as exc:
6472
if exc.response is not None and exc.response.content:
@@ -84,7 +92,8 @@ def put(url, data): # type: (str, dict) -> requests.Response
8492
LOG.debug('PUT %s, data=%r', url, data)
8593

8694
try:
87-
rsp = requests.patch(url, auth=_get_auth(), data=data)
95+
rsp = requests.patch(url, auth=_get_auth(), headers=_get_headers(),
96+
data=data)
8897
rsp.raise_for_status()
8998
except requests.exceptions.RequestException as exc:
9099
if exc.response is not None and exc.response.content:

0 commit comments

Comments
 (0)