Skip to content

Commit

Permalink
Issue #590 - Allow proxy_request to take a headers argument.
Browse files Browse the repository at this point in the history
Which will be merged with the AUTH_HEADERS and sent to github.
  • Loading branch information
Mike Taylor committed Apr 10, 2015
1 parent 67f0811 commit a95647f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions webcompat/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,33 @@
from webcompat import github

REPO_URI = app.config['ISSUES_REPO_URI']
headers = {'Authorization': 'token {0}'.format(app.config['BOT_OAUTH_TOKEN']),
'User-Agent': 'webcompat/webcompat-bot'}
BOT_TOKEN = app.config['BOT_OAUTH_TOKEN']
AUTH_HEADERS = {'Authorization': 'token {0}'.format(BOT_TOKEN),
'User-Agent': 'webcompat/webcompat-bot'}


def proxy_request(method, path_mod='', data=None, params=None, uri=None):
def proxy_request(method, path_mod='', data=None, params=None, uri=None,
headers=None):
'''Make a GitHub API request with a bot's OAuth token.
Necessary for non-logged in users.
* `path`, if included, will be appended to the end of the URI.
* Optionally pass in POST data via the `data` arg.
* Optionally point to a different URI via the `uri` arg.
* Optionally pass in HTTP headers to forward.
'''
# We capture the etag of the request and sends it back to github
if 'If-None-Match' in headers:
etag = g.request_headers['If-None-Match'].encode('utf-8')
headers['If-None-Match'] = etag
# Merge passed in headers with AUTH_HEADERS, and add the etag of the
# request, if it exists, to be sent back to GitHub.
merged_headers = AUTH_HEADERS.copy()
merged_headers.update(headers)
# Preparing the requests
req = getattr(requests, method)
if uri:
req_uri = uri
else:
req_uri = 'https://api.github.com/repos/{0}{1}'.format(REPO_URI,
path_mod)
return req(req_uri, data=data, params=params, headers=headers)
return req(req_uri, data=data, params=params, headers=merged_headers)


def report_issue(form, proxy=False):
Expand Down

0 comments on commit a95647f

Please sign in to comment.