Skip to content

Commit

Permalink
Merge pull request #8 from fullofcaffeine/master
Browse files Browse the repository at this point in the history
Allow passing and setting the Accept header for `_req`
  • Loading branch information
alkovpro authored Aug 10, 2017
2 parents e971cab + 62ab1af commit 563743f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions youtrack/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,18 @@ def _login(self, login, password):
'Cache-Control': 'no-cache'}

@relogin_on_401
def _req(self, method, url, body=None, ignore_status=None, content_type=None):
def _req(self, method, url, body=None, ignore_status=None, content_type=None, accept_header=None):
headers = self.headers
headers = headers.copy()
if method == 'PUT' or method == 'POST':
headers = headers.copy()
if content_type is None:
content_type = 'application/xml; charset=UTF-8'
headers['Content-Type'] = content_type
headers['Content-Length'] = str(len(body)) if body else '0'

if accept_header is not None:
headers['Accept'] = accept_header

response, content = self.http.request(self.base_url + url, method, headers=headers, body=body)
content = content.translate(None, '\0'.encode('utf-8'))
_illegal_unichrs = [(0x00, 0x08), (0x0B, 0x0C), (0x0E, 0x1F),
Expand Down Expand Up @@ -729,7 +732,7 @@ def get_number_of_issues(self, _filter='', wait_for_server=True):
while True:
url_filter_list = [('filter', _filter)]
final_url = '/issue/count?' + urllib.parse.urlencode(url_filter_list)
response, content = self._req('GET', final_url)
response, content = self._req('GET', final_url, None, None, None, 'application/json')
result = eval(content.replace('callback'.encode('utf-8'), ''.encode('utf-8')))
number_of_issues = result['value']
if not wait_for_server:
Expand Down

0 comments on commit 563743f

Please sign in to comment.