in uber_rides/request.py [0:0]
def _build_headers(self, method, auth_session):
"""Create headers for the request.
Parameters
method (str)
HTTP method (e.g. 'POST').
auth_session (Session)
The Session object containing OAuth 2.0 credentials.
Returns
headers (dict)
Dictionary of access headers to attach to request.
Raises
UberIllegalState (ApiError)
Raised if headers are invalid.
"""
token_type = auth_session.token_type
if auth_session.server_token:
token = auth_session.server_token
else:
token = auth_session.oauth2credential.access_token
if not self._authorization_headers_valid(token_type, token):
message = 'Invalid token_type or token.'
raise UberIllegalState(message)
headers = {
'Authorization': ' '.join([token_type, token]),
'X-Uber-User-Agent': 'Python Rides SDK v{}'.format(LIB_VERSION),
}
if method in http.BODY_METHODS:
headers.update(http.DEFAULT_CONTENT_HEADERS)
return headers