Skip to content

Some servers don't return content type, including truly restful api's during DELETE #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions flask_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def get_etree():


def parse_response(resp, content, strict=False):
ct, options = parse_options_header(resp['content-type'])
content_type = resp.get('content-type', 'text/html')
ct, options = parse_options_header(content_type)
if ct in ('application/json', 'text/javascript'):
return json.loads(content)
elif ct in ('application/xml', 'text/xml'):
Expand Down Expand Up @@ -222,13 +223,15 @@ def put(self, *args, **kwargs):
:meth:`request`.
"""
kwargs['method'] = 'PUT'
kwargs['format'] = 'urlencoded'
return self.request(*args, **kwargs)

def delete(self, *args, **kwargs):
"""Sends a ``DELETE`` request. Accepts the same parameters as
:meth:`request`.
"""
kwargs['method'] = 'DELETE'
kwargs['format'] = 'urlencoded'
return self.request(*args, **kwargs)

def make_client(self, token=None):
Expand Down Expand Up @@ -271,16 +274,19 @@ def request(self, url, data="", headers=None, format='urlencoded',
headers = dict(headers or {})
client = self.make_client(token)
url = self.expand_url(url)
if method == 'GET':
if method in ['GET', 'PUT', 'DELETE']:
assert format == 'urlencoded'
if data:
url = add_query(url, data)
url = add_query(url, data).replace('%2C', ',')
data = ""
else:
if content_type is None:
data, content_type = encode_request_data(data, format)
if content_type is not None:
headers['Content-Type'] = content_type

data = data.replace('%2C', ',')

return OAuthResponse(*client.request(url, method=method,
body=data or '',
headers=headers))
Expand Down