From 0a7dfca0e4783abc24a6ec9d0bd9b84219593a1f Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Thu, 20 Sep 2012 11:07:11 -0400 Subject: [PATCH] Fix JSON postback error where the content-type header line can contain more info than just the application/json descriptor. Now we just to a compare on the start of the header value. --- common/djangoapps/util/json_request.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/util/json_request.py b/common/djangoapps/util/json_request.py index 391905e574..169a7e3fb4 100644 --- a/common/djangoapps/util/json_request.py +++ b/common/djangoapps/util/json_request.py @@ -6,7 +6,9 @@ import json def expect_json(view_function): @wraps(view_function) def expect_json_with_cloned_request(request, *args, **kwargs): - if request.META['CONTENT_TYPE'] == "application/json": + # cdodge: fix postback errors in CMS. The POST 'content-type' header can include additional information + # e.g. 'charset', so we can't do a direct string compare + if request.META['CONTENT_TYPE'].lower().startswith("application/json"): cloned_request = copy.copy(request) cloned_request.POST = cloned_request.POST.copy() cloned_request.POST.update(json.loads(request.body))