diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 835270e3..127af666 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -637,13 +637,13 @@ def set_signature_method(self, method): self.method = method def request(self, uri, method="GET", body='', headers=None, - redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None): + redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None, realm=None): DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded' if not isinstance(headers, dict): headers = {} - if method == "POST": + if method == "POST" and 'Content-Type' not in headers: headers['Content-Type'] = headers.get('Content-Type', DEFAULT_POST_CONTENT_TYPE) @@ -661,14 +661,15 @@ def request(self, uri, method="GET", body='', headers=None, req.sign_request(self.method, self.consumer, self.token) - schema, rest = urllib.splittype(uri) - if rest.startswith('//'): - hierpart = '//' - else: - hierpart = '' - host, rest = urllib.splithost(rest) + if not realm: + schema, rest = urllib.splittype(uri) + if rest.startswith('//'): + hierpart = '//' + else: + hierpart = '' + host, rest = urllib.splithost(rest) - realm = schema + ':' + hierpart + host + realm = schema + ':' + hierpart + host if is_form_encoded: body = req.to_postdata()