Skip to content

Commit d536d79

Browse files
committed
[PROD-899] report library name and version in X-Pusher-Library header
1 parent ae73d77 commit d536d79

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

pusher/http.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
division)
55
from pusher.errors import *
66
from pusher.signature import sign
7+
from pusher.version import VERSION
78

89
import copy
910
import hashlib
@@ -117,7 +118,7 @@ def base_url(self):
117118

118119
@property
119120
def headers(self):
121+
hdrs = {"X-Pusher-Library": "pusher-http-python " + VERSION}
120122
if self.method == POST:
121-
return {"Content-Type": "application/json"}
122-
else:
123-
return {}
123+
hdrs["Content-Type"] = "application/json"
124+
return hdrs

pusher_tests/test_request.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ def test_post_signature_generation(self):
4141
}
4242

4343
with mock.patch('time.time', return_value=1000):
44-
# patching this, because json can be unambiguously parsed, but not
44+
# patching this, because json can be unambiguously parsed, but not
4545
# unambiguously generated (think whitespace).
4646
with mock.patch('json.dumps', return_value='{"foo": "bar"}') as json_dumps_mock:
4747
req = Request(conf, u'POST', u'/some/obscure/api', {u'foo': u'bar'})
4848
self.assertEqual(req.query_params, expected)
4949

5050
json_dumps_mock.assert_called_once_with({u"foo": u"bar"})
5151

52+
def test_x_pusher_library_header(self):
53+
req = Request(conf, u'POST', u'/some/obscure/api', {u'foo': u'bar'})
54+
self.assertEqual(req.headers(), {})
55+
5256
if __name__ == '__main__':
5357
unittest.main()

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# -*- coding: utf-8 -*-
22
from setuptools import setup
3+
4+
from pusher.version import VERSION
5+
36
setup(
47
name='pusher',
5-
version='1.4rc3',
8+
version=VERSION,
69
description='A Python library to interract with the Pusher API',
710
url='https://github.com/pusher/pusher-http-python',
811
author='Pusher',

0 commit comments

Comments
 (0)