Skip to content

Commit 9df062b

Browse files
committed
default body is the empty string rather than None; add the Realm header
1 parent bac9dfd commit 9df062b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

oauth2/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class Request(dict):
319319
version = OAUTH_VERSION
320320

321321
def __init__(self, method=HTTP_METHOD, url=None, parameters=None,
322-
body=None, is_form_encoded=False):
322+
body='', is_form_encoded=False):
323323
if url is not None:
324324
self.url = to_unicode(url)
325325
self.method = method
@@ -517,7 +517,7 @@ def from_request(cls, http_method, http_url, headers=None, parameters=None,
517517
@classmethod
518518
def from_consumer_and_token(cls, consumer, token=None,
519519
http_method=HTTP_METHOD, http_url=None, parameters=None,
520-
body=None, is_form_encoded=False):
520+
body='', is_form_encoded=False):
521521
if not parameters:
522522
parameters = {}
523523

@@ -603,7 +603,7 @@ def set_signature_method(self, method):
603603

604604
self.method = method
605605

606-
def request(self, uri, method="GET", body=None, headers=None,
606+
def request(self, uri, method="GET", body='', headers=None,
607607
redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None):
608608
DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded'
609609

@@ -628,12 +628,21 @@ def request(self, uri, method="GET", body=None, headers=None,
628628

629629
req.sign_request(self.method, self.consumer, self.token)
630630

631+
schema, rest = urllib.splittype(uri)
632+
if rest.startswith('//'):
633+
hierpart = '//'
634+
else:
635+
hierpart = ''
636+
host, rest = urllib.splithost(rest)
637+
638+
realm = schema + ':' + hierpart + host
639+
631640
if is_form_encoded:
632641
body = req.to_postdata()
633642
elif method == "GET":
634643
uri = req.to_url()
635644
else:
636-
headers.update(req.to_header())
645+
headers.update(req.to_header(realm=realm))
637646

638647
return httplib2.Http.request(self, uri, method=method, body=body,
639648
headers=headers, redirections=redirections,

0 commit comments

Comments
 (0)