Skip to content

Commit 01ad3d8

Browse files
committed
refactor internals of the way Client.request() decides whether this is a x-www-form-urlencoded request or not
1 parent 3350bae commit 01ad3d8

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

oauth2/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -600,15 +600,19 @@ def set_signature_method(self, method):
600600

601601
def request(self, uri, method="GET", body=None, headers=None,
602602
redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None):
603-
DEFAULT_CONTENT_TYPE = 'application/x-www-form-urlencoded'
603+
DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded'
604604

605605
if not isinstance(headers, dict):
606606
headers = {}
607607

608-
is_multipart = method == 'POST' and headers.get('Content-Type',
609-
DEFAULT_CONTENT_TYPE) != DEFAULT_CONTENT_TYPE
608+
if method == "POST":
609+
headers['Content-Type'] = headers.get('Content-Type',
610+
DEFAULT_POST_CONTENT_TYPE)
610611

611-
if body and method == "POST" and not is_multipart:
612+
is_form_encoded = \
613+
headers.get('Content-Type') == 'application/x-www-form-urlencoded'
614+
615+
if is_form_encoded and body:
612616
parameters = dict(parse_qsl(body))
613617
else:
614618
parameters = None
@@ -620,12 +624,10 @@ def request(self, uri, method="GET", body=None, headers=None,
620624
req.sign_request(self.method, self.consumer, self.token)
621625

622626
if method == "POST":
623-
headers['Content-Type'] = headers.get('Content-Type',
624-
DEFAULT_CONTENT_TYPE)
625-
if is_multipart:
626-
headers.update(req.to_header())
627-
else:
627+
if is_form_encoded:
628628
body = req.to_postdata()
629+
else:
630+
headers.update(req.to_header())
629631
elif method == "GET":
630632
uri = req.to_url()
631633
else:

0 commit comments

Comments
 (0)