Permalink
Browse files

Fix bug in post content-type: application/json

  • Loading branch information...
1 parent 24098ce commit 0202b1f87c5c3db55ea4a6e7c618bcd8bec3b4ab @nycholas nycholas committed Dec 15, 2012
Showing with 13 additions and 8 deletions.
  1. +13 −8 flask_jsonrpc/site.py
View
@@ -98,16 +98,20 @@ def __init__(self):
def register(self, name, method):
self.urls[unicode(name)] = method
- def extract_id_request(self, immutable_multi_dict):
- raw_data = None
- if not immutable_multi_dict is None and immutable_multi_dict.keys():
- raw_data = immutable_multi_dict.keys()[0]
+ def extract_id_request(self, raw_data):
if not raw_data is None and raw_data.find('id') != -1:
- find_id = re.findall(r'["|\']id["|\']:["|\'](.+?)["|\']',
+ find_id = re.findall(r'["|\']id["|\']:([0-9])|["|\']id["|\']:["|\'](.+?)["|\']',
raw_data.replace(' ', ''), re.U)
- return find_id[0] if find_id else None
+ if find_id:
+ g1, g2 = find_id[0]
+ return g1 if g1 else g2
return None
+ def extract_raw_data_request(self, request):
+ if request.data:
+ return request.data
+ return request.form.keys()[0]
+
def empty_response(self, version='2.0'):
resp = {'id': None}
if version == '1.1':
@@ -215,6 +219,7 @@ def dispatch(self, request, method=''):
# in case we do something json doesn't like, we always get back valid
# json-rpc response
response = self.empty_response()
+ raw_data = self.extract_raw_data_request(request)
try:
if request.method == 'GET':
@@ -226,7 +231,7 @@ def dispatch(self, request, method=''):
raise RequestPostError
else:
try:
- D = json.loads(request.form.keys()[0])
+ D = json.loads(raw_data)
except:
raise InvalidRequestError
@@ -255,7 +260,7 @@ def dispatch(self, request, method=''):
status = other_error.status
# extract id the request
- json_request_id = self.extract_id_request(request.form)
+ json_request_id = self.extract_id_request(raw_data)
response['id'] = json_request_id
return response

0 comments on commit 0202b1f

Please sign in to comment.