Skip to content

Commit 201b4e2

Browse files
committed
Consolidate rpc Proxy headers in single class property
1 parent d3fea9c commit 201b4e2

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

bitcoin/rpc.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,8 @@ def __init__(self,
237237
self.__conn = httplib.HTTPConnection(self.__url.hostname, port=port,
238238
timeout=timeout)
239239

240-
def _call(self, service_name, *args):
241-
self.__id_count += 1
242-
243-
postdata = json.dumps({'version': '1.1',
244-
'method': service_name,
245-
'params': args,
246-
'id': self.__id_count})
247-
240+
@property
241+
def _headers(self):
248242
headers = {
249243
'Host': self.__url.hostname,
250244
'User-Agent': DEFAULT_USER_AGENT,
@@ -254,7 +248,18 @@ def _call(self, service_name, *args):
254248
if self.__auth_header is not None:
255249
headers['Authorization'] = self.__auth_header
256250

257-
self.__conn.request('POST', self.__url.path, postdata, headers)
251+
return headers
252+
253+
def _call(self, service_name, *args):
254+
self.__id_count += 1
255+
256+
postdata = json.dumps({'version': '1.1',
257+
'method': service_name,
258+
'params': args,
259+
'id': self.__id_count})
260+
261+
262+
self.__conn.request('POST', self.__url.path, postdata, self._headers)
258263

259264
response = self._get_response()
260265
err = response.get('error')
@@ -272,17 +277,7 @@ def _call(self, service_name, *args):
272277

273278
def _batch(self, rpc_call_list):
274279
postdata = json.dumps(list(rpc_call_list))
275-
276-
headers = {
277-
'Host': self.__url.hostname,
278-
'User-Agent': DEFAULT_USER_AGENT,
279-
'Content-type': 'application/json',
280-
}
281-
282-
if self.__auth_header is not None:
283-
headers['Authorization'] = self.__auth_header
284-
285-
self.__conn.request('POST', self.__url.path, postdata, headers)
280+
self.__conn.request('POST', self.__url.path, postdata, self._headers)
286281
return self._get_response()
287282

288283
def _get_response(self):

0 commit comments

Comments
 (0)