Skip to content
Myr

Correct OAuth1 with query or data.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ayanamist · committed by ayanamist · parent b9ecf45 · Browse files · 1 file+25 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+25 added−24 removed

  • other:+25 added−24 removed

1 file+25 added−24 removed

modified:requests/auth.py+25 added-24 removed
31 unmodified lines
3233log = logging.getLogger(__name__)3435CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'36CONTENT_TYPE_MULTI_PART = 'multipart/form-data'373839def _basic_auth_str(username, password):40 """Returns a Basic Auth string."""
33 unmodified lines
7475 Parameters may be included from the body if the content-type is76 urlencoded, if no content type is set an educated guess is made.77 """78 # split(";") because Content-Type may be "multipart/form-data; boundary=xxxxx"77 contenttype = r.headers.get('Content-Type', None)79 contenttype = r.headers.get('Content-Type', '').split(";")[0].lower()80 # extract_params will not give params unless the body is a properly81 # formatted string, a dictionary or a list of 2-tuples.82 decoded_body = extract_params(r.data)8382 _ct = (contenttype is None)83 _ct = _ct or contenttype.lower() == CONTENT_TYPE_FORM_URLENCODED8485 if _ct and decoded_body != None:86 # extract_params can only check the present r.data and does not know87 # of r.files, thus an extra check is performed. We know that88 # if files are present the request will not have89 # Content-type: x-www-form-urlencoded. We guess it will have90 # a mimetype of multipart/form-encoded and if this is not the case91 # we assume the correct header will be set later.92 if r.files:93 # Omit body data in the signing and since it will always94 # be empty (cant add paras to body if multipart) and we wish95 # to preserve body.96 r.headers['Content-Type'] = 'multipart/form-encoded'97 r.url, r.headers, _ = self.client.sign(98 unicode(r.full_url), unicode(r.method), None, r.headers)99 else:100 # Normal signing101 r.headers['Content-Type'] = 'application/x-www-form-urlencoded'102 r.url, r.headers, r.data = self.client.sign(103 unicode(r.full_url), unicode(r.method), r.data, r.headers)10484 # extract_params can only check the present r.data and does not know85 # of r.files, thus an extra check is performed. We know that86 # if files are present the request will not have87 # Content-type: x-www-form-urlencoded. We guess it will have88 # a mimetype of multipart/form-encoded and if this is not the case89 # we assume the correct header will be set later.90 _cond = True91 if r.files and contenttype == CONTENT_TYPE_MULTI_PART:92 # Omit body data in the signing and since it will always93 # be empty (cant add paras to body if multipart) and we wish94 # to preserve body.95 r.headers['Content-Type'] = CONTENT_TYPE_MULTI_PART96 r.url, r.headers, _ = self.client.sign(97 unicode(r.full_url), unicode(r.method), None, r.headers)98 elif decoded_body != None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):99 # Normal signing100 r.headers['Content-Type'] = CONTENT_TYPE_FORM_URLENCODED101 r.url, r.headers, r.data = self.client.sign(102 unicode(r.full_url), unicode(r.method), r.data, r.headers)103 else:104 _cond = False105 if _cond:106 # Both flows add params to the URL by using r.full_url,107 # so this prevents adding it again later108 r.params = {}109
273 unmodified lines